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 AddRelatedContentCommand : IRequest { public Guid TitleId { get; set; } public MediaInfoType Type { get; set; } public Stream Data { get; set; } = default!; public string ContentType { get; set; } = default!; } public class AddRelatedContentCommandHandler(IAnimeTitleGateway titleGateway, IMediator mediator) : IRequestHandler { public async Task Handle(AddRelatedContentCommand request, CancellationToken cancellationToken) { var title = await titleGateway.GetById(request.TitleId); var objectId = await mediator.Send(new AddObjectCommand { //ObjectName = !string.IsNullOrWhiteSpace(user.AvatarId) ? user.AvatarId : null, ObjectName = request.TitleId.ToString(), BusketName = "my-bookmark.library", ObjectPrefix = "preview", //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.AddRelatedContent(objectId, (Domain.Entities.MediaInfoType)request.Type, request.ContentType); await titleGateway.Update(title); return Unit.Value; } }