REST API #2d: Playouts create/delete #37

Closed
opened 2026-06-27 13:46:18 +02:00 by timothy · 2 comments
Owner

Part of #2 (REST API tracker). Design: docs/rest-api.md. Depends on #2a foundation.

Slice #2d — Playouts.

  • POST /api/playouts (create — link channel↔schedule) · GET /api/playouts · GET /api/playouts/{id} · DELETE /api/playouts/{id}.
  • Keep existing POST /api/channels/{number}/playout/reset.
  • Map a discriminated create DTO → existing CreateClassicPlayout (+ Block / Sequential / Scripted / ExternalJson kinds) and DeletePlayout (all Either<BaseError, _>).

Validation already strong in handlers: "Channel already has one playout" (1:1), "Program schedule must have items", channel/schedule existence → map to 422/404.

Tests: handler unit (success + 404/422 incl. the 1:1 and has-items rules), controller mapping, create→delete EF integration (proves cascade cleanup).

Part of #2 (REST API tracker). Design: `docs/rest-api.md`. Depends on #2a foundation. **Slice #2d — Playouts.** - `POST /api/playouts` (create — link channel↔schedule) · `GET /api/playouts` · `GET /api/playouts/{id}` · `DELETE /api/playouts/{id}`. - Keep existing `POST /api/channels/{number}/playout/reset`. - Map a discriminated create DTO → existing `CreateClassicPlayout` (+ `Block` / `Sequential` / `Scripted` / `ExternalJson` kinds) and `DeletePlayout` (all `Either<BaseError, _>`). Validation already strong in handlers: "Channel already has one playout" (1:1), "Program schedule must have items", channel/schedule existence → map to 422/404. Tests: handler unit (success + 404/422 incl. the 1:1 and has-items rules), controller mapping, create→delete EF integration (proves cascade cleanup).
Author
Owner

Working #37 in isolated worktree /private/tmp/ersatztv-issue37-rest-api-playouts from current origin/main (4f8b3042).

Approach after characterization:

  • Reuse existing playout MediatR handlers rather than adding new business logic.
  • Add POST /api/playouts with a stable request DTO using channelId + programScheduleId for classic playout creation.
  • Add DELETE /api/playouts/{id} using the existing delete command.
  • Return PlayoutNameViewModel as the stable response body by reading the created playout with GetPlayoutById; Location will be /api/playouts/{id}.
  • Preserve the #46 ProblemDetails contract for 404/422 and convert missing referenced resources/playouts to NotFoundError where needed.
  • Add controller, metadata/OpenAPI, handler, and EF integration tests first, then implement the minimal production code.
Working #37 in isolated worktree `/private/tmp/ersatztv-issue37-rest-api-playouts` from current `origin/main` (`4f8b3042`). Approach after characterization: - Reuse existing playout MediatR handlers rather than adding new business logic. - Add `POST /api/playouts` with a stable request DTO using `channelId` + `programScheduleId` for classic playout creation. - Add `DELETE /api/playouts/{id}` using the existing delete command. - Return `PlayoutNameViewModel` as the stable response body by reading the created playout with `GetPlayoutById`; `Location` will be `/api/playouts/{id}`. - Preserve the #46 ProblemDetails contract for 404/422 and convert missing referenced resources/playouts to `NotFoundError` where needed. - Add controller, metadata/OpenAPI, handler, and EF integration tests first, then implement the minimal production code.
Author
Owner

Done

What was done: Implemented REST API #2d playout create/delete in PR #51. Added GET /api/playouts/{id}, POST /api/playouts, and DELETE /api/playouts/{id}. Create uses a stable channelId + programScheduleId request DTO, delegates to CreateClassicPlayout, returns 201 Created with Location: /api/playouts/{id} and PlayoutResponseModel; delete delegates to DeletePlayout and returns 204 No Content. Missing channel/schedule/playout now returns typed NotFoundError so REST mapping produces 404 ProblemDetails; validation/business failures remain 422 ProblemDetails. Existing reset endpoint remains unchanged.

Root cause: n/a — feature slice, not a bug fix.

Files changed: ErsatzTV/Controllers/Api/PlayoutController.cs, ErsatzTV/Controllers/Api/Requests/CreatePlayoutRequest.cs, ErsatzTV.Core/Api/Playouts/PlayoutResponseModel.cs, playout create/delete handlers, playout controller/handler/integration tests, API metadata/OpenAPI contract tests, and regenerated ErsatzTV/wwwroot/openapi/v1.json.

Verification: LSP diagnostics clean for changed C# files; scripts/update-openapi.sh; dotnet build ErsatzTV.sln (0 warnings, 0 errors); TZ=UTC dotnet test ErsatzTV.sln -v normal (223 passed, 0 failed); adversarial review run and one real test gap fixed; PR #51 CI green (Build & test (.NET) success, EF migration integrity (SQLite + MySql) success).

Deferred: Full HTTP pipeline test coverage was not added; this follows the adjacent REST slices' current controller-unit + handler/EF integration coverage pattern.

Follow-up issues: n/a.

Docs updated: Static OpenAPI contract updated in ErsatzTV/wwwroot/openapi/v1.json; no operational docs impact and no DB migrations required.

## Done **What was done**: Implemented REST API #2d playout create/delete in PR #51. Added `GET /api/playouts/{id}`, `POST /api/playouts`, and `DELETE /api/playouts/{id}`. Create uses a stable `channelId` + `programScheduleId` request DTO, delegates to `CreateClassicPlayout`, returns `201 Created` with `Location: /api/playouts/{id}` and `PlayoutResponseModel`; delete delegates to `DeletePlayout` and returns `204 No Content`. Missing channel/schedule/playout now returns typed `NotFoundError` so REST mapping produces `404 ProblemDetails`; validation/business failures remain `422 ProblemDetails`. Existing reset endpoint remains unchanged. **Root cause**: n/a — feature slice, not a bug fix. **Files changed**: `ErsatzTV/Controllers/Api/PlayoutController.cs`, `ErsatzTV/Controllers/Api/Requests/CreatePlayoutRequest.cs`, `ErsatzTV.Core/Api/Playouts/PlayoutResponseModel.cs`, playout create/delete handlers, playout controller/handler/integration tests, API metadata/OpenAPI contract tests, and regenerated `ErsatzTV/wwwroot/openapi/v1.json`. **Verification**: LSP diagnostics clean for changed C# files; `scripts/update-openapi.sh`; `dotnet build ErsatzTV.sln` (0 warnings, 0 errors); `TZ=UTC dotnet test ErsatzTV.sln -v normal` (223 passed, 0 failed); adversarial review run and one real test gap fixed; PR #51 CI green (`Build & test (.NET)` success, `EF migration integrity (SQLite + MySql)` success). **Deferred**: Full HTTP pipeline test coverage was not added; this follows the adjacent REST slices' current controller-unit + handler/EF integration coverage pattern. **Follow-up issues**: n/a. **Docs updated**: Static OpenAPI contract updated in `ErsatzTV/wwwroot/openapi/v1.json`; no operational docs impact and no DB migrations required.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#37