Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user