Files
TelegramMemeVault/src/MemeVault.Application/Commands/CreateCollection/CreateCollectionCommandHandler.cs
T
2026-09-28 01:47:01 +04:00

27 lines
934 B
C#

using MediatR;
using MemeVault.Application.Common;
using MemeVault.Domain.Aggregates.Collection;
using MemeVault.Domain.Repositories;
namespace MemeVault.Application.Commands.CreateCollection;
public sealed class CreateCollectionCommandHandler : IRequestHandler<CreateCollectionCommand, Guid>
{
private readonly ICollectionRepository _collections;
private readonly IUnitOfWork _uow;
public CreateCollectionCommandHandler(ICollectionRepository collections, IUnitOfWork uow)
{
_collections = collections;
_uow = uow;
}
public async Task<Guid> Handle(CreateCollectionCommand request, CancellationToken cancellationToken)
{
var collection = Collection.Create(request.OwnerTelegramId, request.Name, request.Description);
await _collections.AddAsync(collection, cancellationToken);
await _uow.SaveChangesAsync(cancellationToken);
return collection.Id;
}
}