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 EditRelatedContentCommand : IRequest { public Guid TitleId { get; set; } public MediaInfoType Type { get; set; } public string ObjectId { get; set; } = default!; public string ContentType { get; set; } = default!; public MediaInfoType? NewType { get; set; } public Stream? Data { get; set; } public string? NewContentType { get; set; } } public class EditRelatedContentCommandHandler(IAnimeTitleGateway titleGateway, IMediator mediator) : IRequestHandler { public async Task Handle(EditRelatedContentCommand 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 objectId = request.ObjectId; if (request.Data != null) { objectId = await mediator.Send(new AddObjectCommand { ObjectName = request.ObjectId, BusketName = "my-bookmark.library", ObjectPrefix = "related_content", //ObjectExtension = relatedContentItem.ex, //get extension from mime-type ObjectExtension = "png", ContentType = request.ContentType, Data = request.Data, }, cancellationToken) ?? throw new Exception("Related content is not set"); } title.CommonProperties.EditRelatedContent(mediaInfo, objectId, (Domain.Entities.MediaInfoType?)request.NewType, request.NewContentType); return Unit.Value; } }