MyBookmark/Modules.Library.Application/Commands/Anime/Title/Properties/RelatedContent/DeleteRelatedContentCommand.cs
2024-11-16 02:52:33 +03:00

35 lines
1.4 KiB
C#

using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Modules.Library.Application.Commands.CommonModels;
using Modules.Library.Application.Gateways;
using Modules.Media.Api.Commands;
namespace Modules.Library.Application.Commands.Anime.Title.Properties.RelatedContent;
public class DeleteRelatedContentCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public MediaInfoType Type { get; set; }
public string ObjectId { get; set; } = default!;
public string ContentType { get; set; } = default!;
}
public class DeleteRelatedContentCommandHandler(IAnimeTitleGateway titleGateway, IMediator mediator) : IRequestHandler<DeleteRelatedContentCommand, Unit>
{
public async Task<Unit> Handle(DeleteRelatedContentCommand request, CancellationToken cancellationToken)
{
var title = await titleGateway.GetById(request.TitleId);
var mediaInfo = new Domain.Entities.MediaInfo(request.ObjectId, (Domain.Entities.MediaInfoType)request.Type, request.ContentType);
var deleted = await mediator.Send(new DeleteObjectCommand
{
BusketName = "my-bookmark.library",
ObjectName = mediaInfo.ObjectId,
}, cancellationToken);
if (deleted)
{
title.CommonProperties.RemoveRelatedContent(mediaInfo);
await titleGateway.Update(title);
}
return Unit.Value;
}
}