27 lines
1.1 KiB
C#
27 lines
1.1 KiB
C#
using MediatR;
|
|
using Modules.Library.Application.Commands.CommonModels;
|
|
using Modules.Library.Application.Gateways;
|
|
using Modules.Library.Domain.Entities.MediaContent.Items.Anime;
|
|
|
|
namespace Modules.Library.Application.Commands.Anime.Season.Properties.RelatedContent;
|
|
|
|
public class AddRelatedContentCommand : IRequest<Unit>
|
|
{
|
|
public Guid TitleId { get; set; }
|
|
public Guid SeasonId { get; set; }
|
|
public MediaInfoType Type { get; set; }
|
|
public string Url { get; set; } = default!;
|
|
}
|
|
|
|
public class AddRelatedContentCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<AddRelatedContentCommand, Unit>
|
|
{
|
|
public async Task<Unit> Handle(AddRelatedContentCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var title = await titleGateway.GetById(request.TitleId);
|
|
var season = title.Items.OfType<AnimeSeason>().FirstOrDefault(q => q.Id == request.SeasonId) ??
|
|
throw new Exception("Season not found");
|
|
season.CommonProperties.AddRelatedContent(request.Url, (Domain.Entities.MediaInfoType)request.Type);
|
|
await titleGateway.Update(title);
|
|
return Unit.Value;
|
|
}
|
|
} |