Files
ersatztv/ErsatzTV.Application/Troubleshooting/Queries/ValidateSequentialScheduleHandler.cs
T
timothyandClaude Fable 5 f0a423c2de feat(api): block-playout history + sequential-schedule validation endpoints
Adds the REST surface for the #145 troubleshooting leftovers (#158 items 4-5):

- GET /api/playouts/{id}/blocks - blocks a block playout schedules
- GET /api/playouts/{id}/blocks/{blockId}/history - paged block history
- GET /api/playouts/history/{id} - decode a history row by id
- POST /api/troubleshoot/validate-schedule - validate sequential YAML

New MediatR queries GetPlayoutHistoryDetails (Either, 404 unknown row /
422 malformed JSON) and ValidateSequentialSchedule (wraps
ISequentialScheduleValidator, never throws). DecodePlayoutHistoryHandler
and the new by-id handler now share PlayoutHistoryDecoder. Regenerated
openapi/v1.json.

Refs #145 #158

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 22:10:37 +02:00

26 lines
1.1 KiB
C#

using ErsatzTV.Core.Interfaces.Scheduling;
namespace ErsatzTV.Application.Troubleshooting.Queries;
public class ValidateSequentialScheduleHandler(ISequentialScheduleValidator validator)
: IRequestHandler<ValidateSequentialSchedule, ValidateSequentialScheduleViewModel>
{
public async Task<ValidateSequentialScheduleViewModel> Handle(
ValidateSequentialSchedule request,
CancellationToken cancellationToken)
{
try
{
// ToJson runs first and can throw on malformed YAML (GetValidationMessages catches its
// own exceptions internally); mirrors the Blazor YamlValidator ordering.
string json = validator.ToJson(request.Yaml);
IList<string> messages = await validator.GetValidationMessages(request.Yaml, request.IsImport);
return new ValidateSequentialScheduleViewModel(messages.Count == 0, messages.ToList(), json);
}
catch (Exception ex)
{
return new ValidateSequentialScheduleViewModel(false, [ex.Message], string.Empty);
}
}
}