MyBookmark/Modules.Library.Application/Commands/Anime/Title/Properties/RelatedContent/DeleteRelatedContentCommand.cs
2024-09-23 03:00:50 +03:00

25 lines
970 B
C#

using MediatR;
using Modules.Library.Application.Commands.CommonModels;
using Modules.Library.Application.Gateways;
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 Url { get; set; } = default!;
}
public class DeleteRelatedContentCommandHandler(IAnimeTitleGateway titleGateway) : 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.Url, (Domain.Entities.MediaInfoType)request.Type);
title.CommonProperties.RemoveRelatedContent(mediaInfo);
await titleGateway.Update(title);
return Unit.Value;
}
}