using System.Threading; using System.Threading.Tasks; using ErsatzTV.Core; using ErsatzTV.Core.Interfaces.Repositories; using LanguageExt; using MediatR; namespace ErsatzTV.Application.FFmpegProfiles.Commands { public class DeleteFFmpegProfileHandler : IRequestHandler> { private readonly IFFmpegProfileRepository _ffmpegProfileRepository; public DeleteFFmpegProfileHandler(IFFmpegProfileRepository ffmpegProfileRepository) => _ffmpegProfileRepository = ffmpegProfileRepository; public async Task> Handle( DeleteFFmpegProfile request, CancellationToken cancellationToken) => (await FFmpegProfileMustExist(request)) .Map(DoDeletion) .ToEither(); private Task DoDeletion(int channelId) => _ffmpegProfileRepository.Delete(channelId); private async Task> FFmpegProfileMustExist( DeleteFFmpegProfile deleteFFmpegProfile) => (await _ffmpegProfileRepository.Get(deleteFFmpegProfile.FFmpegProfileId)) .ToValidation($"FFmpegProfile {deleteFFmpegProfile.FFmpegProfileId} does not exist.") .Map(c => c.Id); } }