fix(api): apply schedule-file update before daily rebuild time in PUT /api/playouts/{id} (#170 review)
A rejected scripted schedule file no longer leaves DailyRebuildTime half-applied; the file update is the only fallible step post-pre-check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -148,25 +148,28 @@ public class PlayoutController(IMediator mediator) : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
// the schedule-file update is the only step that can fail after the pre-checks,
|
||||
// so it goes first — a rejected file must not leave DailyRebuildTime applied
|
||||
if (hasScheduleFile)
|
||||
{
|
||||
foreach (PlayoutNameViewModel playout in maybePlayout)
|
||||
{
|
||||
Either<BaseError, PlayoutNameViewModel> scheduleFileResult =
|
||||
await UpdateScheduleFile(playout, request.ScheduleFile, cancellationToken);
|
||||
foreach (BaseError error in scheduleFileResult.LeftToSeq())
|
||||
{
|
||||
return error.ToErrorResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Option<TimeSpan> dailyRebuildTime = request.DailyRebuildTime is { } t ? Some(t) : Option<TimeSpan>.None;
|
||||
Either<BaseError, PlayoutNameViewModel> result =
|
||||
await mediator.Send(new UpdatePlayout(id, dailyRebuildTime), cancellationToken);
|
||||
|
||||
return await result.Match(
|
||||
Left: error => Task.FromResult(error.ToErrorResult()),
|
||||
Right: async playout =>
|
||||
{
|
||||
if (!hasScheduleFile)
|
||||
{
|
||||
return (IActionResult)new OkObjectResult(ToResponse(playout));
|
||||
}
|
||||
|
||||
Either<BaseError, PlayoutNameViewModel> scheduleFileResult =
|
||||
await UpdateScheduleFile(playout, request.ScheduleFile, cancellationToken);
|
||||
return scheduleFileResult.Match(
|
||||
Left: error => error.ToErrorResult(),
|
||||
Right: updated => (IActionResult)new OkObjectResult(ToResponse(updated)));
|
||||
});
|
||||
return result.Match(
|
||||
Left: error => error.ToErrorResult(),
|
||||
Right: playout => (IActionResult)new OkObjectResult(ToResponse(playout)));
|
||||
}
|
||||
|
||||
private async Task<Either<BaseError, PlayoutNameViewModel>> UpdateScheduleFile(
|
||||
|
||||
Reference in New Issue
Block a user