MyBookmark/Modules.Library.Application/Commands/Anime/Title/RateTitleCommand.cs
2024-10-21 01:52:41 +03:00

25 lines
923 B
C#

using MediatR;
using Modules.Library.Application.Gateways;
using Modules.Rating.Api.Commands;
namespace Modules.Library.Application.Commands.Anime.Title;
public class RateTitleCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public ushort RatePercentage { get; set; }
}
public class RateTitleCommandHandler(IAnimeTitleGateway titleGateway, IMediator mediator) : IRequestHandler<RateTitleCommand, Unit>
{
public async Task<Unit> Handle(RateTitleCommand request, CancellationToken cancellationToken)
{
var subjectId = new Guid("8393230f-78e3-473b-a5dc-3221917e0aeb"); //user
var title = await titleGateway.GetById(request.TitleId);
if (title != null && !title.Deleted)
{
await mediator.Send(new RateObjectCommand { ObjectId = title.Id, SubjectId = subjectId, RatePercentage = request.RatePercentage });
}
return Unit.Value;
}
}