Files
TelegramMemeVault/src/MemeVault.Application/Commands/UpdateCollection/UpdateCollectionCommandHandler.cs
T
CrazyHackGUT 274e60a433 feat: много запланированного
- клонирование коллекции
- добавление паблик-коллекций
- регенерация паблик-ссылок
2026-10-07 02:45:37 +04:00

31 lines
1.3 KiB
C#

using MediatR;
using MemeVault.Application.Common;
using MemeVault.Domain.Exceptions;
using MemeVault.Domain.Repositories;
namespace MemeVault.Application.Commands.UpdateCollection;
public sealed class UpdateCollectionCommandHandler(
ICollectionRepository collections,
IBotUserRepository users,
IUnitOfWork unitOfWork)
: IRequestHandler<UpdateCollectionCommand, bool>
{
public async Task<bool> Handle(UpdateCollectionCommand request, CancellationToken ct)
{
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
// Если коллекции нет или пользователь — не участник, возвращаем 404.
// Если роль ниже Manager — domain.Rename() бросит DomainException.
if (collection is null || collection.GetRole(request.RequestingTelegramId) is null)
return false;
var user = await users.GetByTelegramIdAsync(request.RequestingTelegramId, ct);
if (user?.InboxCollectionId == collection.Id)
throw new DomainException("Cannot rename the Inbox collection.");
collection.Rename(request.Name, request.RequestingTelegramId);
await unitOfWork.SaveChangesAsync(ct);
return true;
}
}