|
|
|
@ -48,7 +48,7 @@ namespace ErsatzTV.Application.Playouts.Commands |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<Validation<BaseError, Playout>> Validate(CreatePlayout request) => |
|
|
|
private async Task<Validation<BaseError, Playout>> Validate(CreatePlayout request) => |
|
|
|
(await ChannelMustExist(request), await ProgramScheduleMustExist(request), ValidatePlayoutType(request)) |
|
|
|
(await ValidateChannel(request), await ProgramScheduleMustExist(request), ValidatePlayoutType(request)) |
|
|
|
.Apply( |
|
|
|
.Apply( |
|
|
|
(channel, programSchedule, playoutType) => new Playout |
|
|
|
(channel, programSchedule, playoutType) => new Playout |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -57,10 +57,19 @@ namespace ErsatzTV.Application.Playouts.Commands |
|
|
|
ProgramSchedulePlayoutType = playoutType |
|
|
|
ProgramSchedulePlayoutType = playoutType |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Task<Validation<BaseError, Channel>> ValidateChannel(CreatePlayout createPlayout) => |
|
|
|
|
|
|
|
ChannelMustExist(createPlayout).BindT(ChannelMustNotHavePlayouts); |
|
|
|
|
|
|
|
|
|
|
|
private async Task<Validation<BaseError, Channel>> ChannelMustExist(CreatePlayout createPlayout) => |
|
|
|
private async Task<Validation<BaseError, Channel>> ChannelMustExist(CreatePlayout createPlayout) => |
|
|
|
(await _channelRepository.Get(createPlayout.ChannelId)) |
|
|
|
(await _channelRepository.Get(createPlayout.ChannelId)) |
|
|
|
.ToValidation<BaseError>("Channel does not exist."); |
|
|
|
.ToValidation<BaseError>("Channel does not exist."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Validation<BaseError, Channel>> ChannelMustNotHavePlayouts(Channel channel) => |
|
|
|
|
|
|
|
Optional(await _channelRepository.CountPlayouts(channel.Id)) |
|
|
|
|
|
|
|
.Filter(count => count == 0) |
|
|
|
|
|
|
|
.Map(_ => channel) |
|
|
|
|
|
|
|
.ToValidation<BaseError>("Channel already has one playout."); |
|
|
|
|
|
|
|
|
|
|
|
private async Task<Validation<BaseError, ProgramSchedule>> ProgramScheduleMustExist( |
|
|
|
private async Task<Validation<BaseError, ProgramSchedule>> ProgramScheduleMustExist( |
|
|
|
CreatePlayout createPlayout) => |
|
|
|
CreatePlayout createPlayout) => |
|
|
|
(await _programScheduleRepository.GetWithPlayouts(createPlayout.ProgramScheduleId)) |
|
|
|
(await _programScheduleRepository.GetWithPlayouts(createPlayout.ProgramScheduleId)) |
|
|
|
|