mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
956 B
23 lines
956 B
using ErsatzTV.Core; |
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
|
|
namespace ErsatzTV.Application.Channels; |
|
|
|
public class DeleteChannelHandler : IRequestHandler<DeleteChannel, Either<BaseError, Task>> |
|
{ |
|
private readonly IChannelRepository _channelRepository; |
|
|
|
public DeleteChannelHandler(IChannelRepository channelRepository) => _channelRepository = channelRepository; |
|
|
|
public async Task<Either<BaseError, Task>> Handle(DeleteChannel request, CancellationToken cancellationToken) => |
|
(await ChannelMustExist(request)) |
|
.Map(DoDeletion) |
|
.ToEither<Task>(); |
|
|
|
private Task DoDeletion(int channelId) => _channelRepository.Delete(channelId); |
|
|
|
private async Task<Validation<BaseError, int>> ChannelMustExist(DeleteChannel deleteChannel) => |
|
(await _channelRepository.Get(deleteChannel.ChannelId)) |
|
.ToValidation<BaseError>($"Channel {deleteChannel.ChannelId} does not exist.") |
|
.Map(c => c.Id); |
|
}
|
|
|