feat: collections controller, healthcheck
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace MemeVault.Application.Commands.DeleteCollection;
|
||||
|
||||
public sealed record DeleteCollectionCommand(
|
||||
Guid CollectionId,
|
||||
long RequestingTelegramId
|
||||
) : IRequest<bool>;
|
||||
@@ -0,0 +1,22 @@
|
||||
using MediatR;
|
||||
using MemeVault.Application.Common;
|
||||
using MemeVault.Domain.Repositories;
|
||||
|
||||
namespace MemeVault.Application.Commands.DeleteCollection;
|
||||
|
||||
public sealed class DeleteCollectionCommandHandler(
|
||||
ICollectionRepository collections,
|
||||
IUnitOfWork unitOfWork)
|
||||
: IRequestHandler<DeleteCollectionCommand, bool>
|
||||
{
|
||||
public async Task<bool> Handle(DeleteCollectionCommand request, CancellationToken ct)
|
||||
{
|
||||
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
|
||||
if (collection is null || collection.OwnerTelegramId != request.RequestingTelegramId)
|
||||
return false;
|
||||
|
||||
await collections.RemoveAsync(collection, ct);
|
||||
await unitOfWork.SaveChangesAsync(ct);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using MediatR;
|
||||
|
||||
namespace MemeVault.Application.Commands.UpdateCollection;
|
||||
|
||||
public sealed record UpdateCollectionCommand(
|
||||
Guid CollectionId,
|
||||
long RequestingTelegramId,
|
||||
string Name,
|
||||
string? Description
|
||||
) : IRequest<bool>;
|
||||
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user