23 lines
770 B
C#
23 lines
770 B
C#
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);
|
|
if (collection is null || collection.OwnerTelegramId != request.RequestingTelegramId)
|
|
return false;
|
|
|
|
collection.Rename(request.Name, request.RequestingTelegramId);
|
|
await unitOfWork.SaveChangesAsync(ct);
|
|
return true;
|
|
}
|
|
}
|