feat: MediaController
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using MediatR;
|
||||
|
||||
namespace MemeVault.Application.Commands.UpdateMedia;
|
||||
|
||||
/// <summary>
|
||||
/// Обновляет caption и/или теги медиа-элемента.
|
||||
/// Tags — полная замена: пустой список очищает все теги.
|
||||
/// </summary>
|
||||
public sealed record UpdateMediaCommand(
|
||||
Guid MediaItemId,
|
||||
long RequestingTelegramId,
|
||||
string? Caption,
|
||||
IReadOnlyList<string> Tags
|
||||
) : IRequest<bool>;
|
||||
@@ -0,0 +1,32 @@
|
||||
using MediatR;
|
||||
using MemeVault.Domain.Repositories;
|
||||
using MemeVault.Domain.ValueObjects;
|
||||
using MemeVault.Application.Common;
|
||||
|
||||
namespace MemeVault.Application.Commands.UpdateMedia;
|
||||
|
||||
public sealed class UpdateMediaCommandHandler(
|
||||
IMediaItemRepository mediaItems,
|
||||
IUnitOfWork unitOfWork)
|
||||
: IRequestHandler<UpdateMediaCommand, bool>
|
||||
{
|
||||
public async Task<bool> Handle(UpdateMediaCommand request, CancellationToken ct)
|
||||
{
|
||||
var item = await mediaItems.GetByIdAsync(request.MediaItemId, ct);
|
||||
|
||||
if (item is null || item.OwnerTelegramId != request.RequestingTelegramId)
|
||||
return false;
|
||||
|
||||
item.UpdateCaption(request.Caption);
|
||||
|
||||
// Полная замена тегов
|
||||
foreach (var tag in item.Tags.ToList())
|
||||
item.RemoveTag(tag);
|
||||
|
||||
foreach (var raw in request.Tags)
|
||||
item.AddTag(new Tag(raw));
|
||||
|
||||
await unitOfWork.SaveChangesAsync(ct);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user