feat: collections controller, healthcheck
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
|
||||
namespace MemeVault.Application.Commands.ManageCollectionItem;
|
||||
|
||||
public sealed record AddItemToCollectionCommand(
|
||||
Guid CollectionId,
|
||||
Guid MediaItemId,
|
||||
long RequestingTelegramId
|
||||
) : IRequest<bool>;
|
||||
|
||||
public sealed record RemoveItemFromCollectionCommand(
|
||||
Guid CollectionId,
|
||||
Guid MediaItemId,
|
||||
long RequestingTelegramId
|
||||
) : IRequest<bool>;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using MediatR;
|
||||
using MemeVault.Application.Common;
|
||||
using MemeVault.Domain.Repositories;
|
||||
|
||||
namespace MemeVault.Application.Commands.ManageCollectionItem;
|
||||
|
||||
public sealed class AddItemToCollectionCommandHandler(
|
||||
ICollectionRepository collections,
|
||||
IUnitOfWork unitOfWork)
|
||||
: IRequestHandler<AddItemToCollectionCommand, bool>
|
||||
{
|
||||
public async Task<bool> Handle(AddItemToCollectionCommand request, CancellationToken ct)
|
||||
{
|
||||
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
|
||||
if (collection is null) return false;
|
||||
|
||||
collection.AddItem(request.MediaItemId, request.RequestingTelegramId);
|
||||
await unitOfWork.SaveChangesAsync(ct);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RemoveItemFromCollectionCommandHandler(
|
||||
ICollectionRepository collections,
|
||||
IUnitOfWork unitOfWork)
|
||||
: IRequestHandler<RemoveItemFromCollectionCommand, bool>
|
||||
{
|
||||
public async Task<bool> Handle(RemoveItemFromCollectionCommand request, CancellationToken ct)
|
||||
{
|
||||
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
|
||||
if (collection is null) return false;
|
||||
|
||||
collection.RemoveItem(request.MediaItemId, request.RequestingTelegramId);
|
||||
await unitOfWork.SaveChangesAsync(ct);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user