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

37 lines
1.6 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.Preview;
public class SetPreviewCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public MediaInfoType Type { get; set; }
public string ContentType { get; set; } = default!;
public Stream Data { get; set; } = default!;
}
public class SetPreviewCommandHandler(IAnimeTitleGateway titleGateway, IMediator mediator) : IRequestHandler<SetPreviewCommand, Unit>
{
public async Task<Unit> Handle(SetPreviewCommand 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("Preview is not set");
title.CommonProperties.SetPreview(objectId, (Domain.Entities.MediaInfoType)request.Type, request.ContentType);
await titleGateway.Update(title);
return Unit.Value;
}
}