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

24 lines
873 B
C#

using MediatR;
using Modules.Library.Application.Gateways;
namespace Modules.Library.Application.Commands.Anime.Title.Properties.Genre;
public class AddGenreCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public Guid GenreId { get; set; }
public decimal? Proportion { get; set; }
}
public class AddGenreCommandHandler(IAnimeTitleGateway titleGateway, IGenreGateway genreGateway) : IRequestHandler<AddGenreCommand, Unit>
{
public async Task<Unit> Handle(AddGenreCommand request, CancellationToken cancellationToken)
{
var title = await titleGateway.GetById(request.TitleId);
if (!await genreGateway.IsGenreExists(request.GenreId)) throw new Exception("NotFound");
title.CommonProperties.AddGenre(request.GenreId, request.Proportion);
await titleGateway.Update(title);
return Unit.Value;
}
}