@ -48,7 +48,7 @@ namespace ErsatzTV.Application.Playouts.Commands
@@ -48,7 +48,7 @@ namespace ErsatzTV.Application.Playouts.Commands
}
private async Task < Validation < BaseError , Playout > > Validate ( CreatePlayout request ) = >
( await ChannelMustExist ( request ) , await ProgramScheduleMustExist ( request ) , ValidatePlayoutType ( request ) )
( await Validate Channel( request ) , await ProgramScheduleMustExist ( request ) , ValidatePlayoutType ( request ) )
. Apply (
( channel , programSchedule , playoutType ) = > new Playout
{
@ -57,10 +57,19 @@ namespace ErsatzTV.Application.Playouts.Commands
@@ -57,10 +57,19 @@ namespace ErsatzTV.Application.Playouts.Commands
ProgramSchedulePlayoutType = playoutType
} ) ;
private Task < Validation < BaseError , Channel > > ValidateChannel ( CreatePlayout createPlayout ) = >
ChannelMustExist ( createPlayout ) . BindT ( ChannelMustNotHavePlayouts ) ;
private async Task < Validation < BaseError , Channel > > ChannelMustExist ( CreatePlayout createPlayout ) = >
( await _ channelRepository . Get ( createPlayout . ChannelId ) )
. 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 (
CreatePlayout createPlayout ) = >
( await _ programScheduleRepository . GetWithPlayouts ( createPlayout . ProgramScheduleId ) )