Files
TelegramMemeVault/src/MemeVault.Application/Commands/UpdateCollection/UpdateCollectionCommandHandler.cs
T

25 lines
995 B
C#
Raw Normal View History

2026-09-28 02:18:57 +04:00
using MediatR;
using MemeVault.Application.Common;
using MemeVault.Domain.Repositories;
namespace MemeVault.Application.Commands.UpdateCollection;
public sealed class UpdateCollectionCommandHandler(
ICollectionRepository collections,
IUnitOfWork unitOfWork)
: IRequestHandler<UpdateCollectionCommand, bool>
{
public async Task<bool> Handle(UpdateCollectionCommand request, CancellationToken ct)
{
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
2026-10-07 02:17:30 +04:00
// Если коллекции нет или пользователь — не участник, возвращаем 404.
// Если роль ниже Manager — domain.Rename() бросит DomainException.
if (collection is null || collection.GetRole(request.RequestingTelegramId) is null)
2026-09-28 02:18:57 +04:00
return false;
collection.Rename(request.Name, request.RequestingTelegramId);
await unitOfWork.SaveChangesAsync(ct);
return true;
}
}