REST API #2c: Schedules CRUD + schedule items (TPT-heavy) #36

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

Part of #2 (REST API tracker). Design: docs/rest-api.md. Depends on #2a foundation. Budget extra — this is the TPT-heavy slice.

Slice #2c — Schedules (ProgramSchedule).

  • POST /api/schedules · GET /api/schedules · GET /api/schedules/{id} · PUT /api/schedules/{id} · DELETE /api/schedules/{id}.
  • Items: GET /api/schedules/{id}/items · POST /api/schedules/{id}/items · PUT /api/schedules/{id}/items (bulk replace) · DELETE /api/schedules/{id}/items/{itemId}.
  • Map DTOs → existing CreateProgramSchedule / UpdateProgramSchedule / DeleteProgramSchedule / AddProgramScheduleItem / ReplaceProgramScheduleItems.

TPT detail: schedule items use the PlayoutMode discriminator (One / Multiple / Flood / Duration) in a flat payload; the handler reconstructs the ProgramScheduleItem TPT subtype rows (ProgramScheduleOneItem / …MultipleItem / …FloodItem / …DurationItem). Design the item DTO to carry the mode + mode-specific fields (Multiple: MultipleMode/Count; Duration: PlayoutDuration/TailMode/DiscardToFillAttempts).

Tests: handler unit (success + 404/422), controller mapping, and an EF integration test proving the correct TPT subtype rows are written for each mode.

Part of #2 (REST API tracker). Design: `docs/rest-api.md`. Depends on #2a foundation. **Budget extra — this is the TPT-heavy slice.** **Slice #2c — Schedules (ProgramSchedule).** - `POST /api/schedules` · `GET /api/schedules` · `GET /api/schedules/{id}` · `PUT /api/schedules/{id}` · `DELETE /api/schedules/{id}`. - Items: `GET /api/schedules/{id}/items` · `POST /api/schedules/{id}/items` · `PUT /api/schedules/{id}/items` (bulk replace) · `DELETE /api/schedules/{id}/items/{itemId}`. - Map DTOs → existing `CreateProgramSchedule` / `UpdateProgramSchedule` / `DeleteProgramSchedule` / `AddProgramScheduleItem` / `ReplaceProgramScheduleItems`. **TPT detail:** schedule items use the `PlayoutMode` discriminator (One / Multiple / Flood / Duration) in a flat payload; the handler reconstructs the `ProgramScheduleItem` TPT subtype rows (`ProgramScheduleOneItem` / `…MultipleItem` / `…FloodItem` / `…DurationItem`). Design the item DTO to carry the mode + mode-specific fields (Multiple: `MultipleMode`/`Count`; Duration: `PlayoutDuration`/`TailMode`/`DiscardToFillAttempts`). Tests: handler unit (success + 404/422), controller mapping, and an **EF integration test proving the correct TPT subtype rows are written** for each mode.
Author
Owner

Starting #36 on branch feature/36-rest-api-schedules in isolated worktree /private/tmp/ersatztv-issue36-rest-api-schedules from origin/main at 0d101e79.

Approach:

  • Characterize existing schedule commands/handlers and TPT item persistence before production changes.
  • Add failing controller/OpenAPI/integration tests first for schedule CRUD, 404/422 ProblemDetails, write-filter metadata, and schedule item subtype rows.
  • Implement thin REST controller + request DTOs over MediatR handlers, preserving the #46 ProblemDetails contract and API-key write filter convention.
  • No migrations expected unless the schedule model unexpectedly needs to change.
Starting #36 on branch `feature/36-rest-api-schedules` in isolated worktree `/private/tmp/ersatztv-issue36-rest-api-schedules` from `origin/main` at `0d101e79`. Approach: - Characterize existing schedule commands/handlers and TPT item persistence before production changes. - Add failing controller/OpenAPI/integration tests first for schedule CRUD, 404/422 `ProblemDetails`, write-filter metadata, and schedule item subtype rows. - Implement thin REST controller + request DTOs over MediatR handlers, preserving the #46 `ProblemDetails` contract and API-key write filter convention. - No migrations expected unless the schedule model unexpectedly needs to change.
Author
Owner

Done

What was done: Implemented schedule REST API slice #2c in PR #50. Added /api/schedules CRUD endpoints plus schedule item list/add/bulk-replace/delete endpoints, request DTOs for the wire contract, explicit PlayoutMode schedule item discriminator, and a DeleteProgramScheduleItem MediatR command/handler. Kept controllers thin over MediatR and reused the #46 ProblemDetails 404/422 result contract and API-key write filter convention.

Root cause: n/a — feature slice.

Files changed: Schedule API controller/request DTOs, schedule command handlers/error mapping, schedule item delete command/handler, controller/API metadata/OpenAPI tests, handler characterization tests, SQLite TPT integration tests, Startup.cs OpenAPI enum schema transformer, and regenerated ErsatzTV/wwwroot/openapi/v1.json.

Verification: LSP diagnostics clean on changed C# files. scripts/update-openapi.sh passed. dotnet build ErsatzTV.sln passed with 0 warnings/errors. TZ=UTC dotnet test ErsatzTV.sln -v normal passed. Gitea Actions run #181 for PR #50 completed successfully: Build & test green, EF migration integrity green, PR image job skipped as expected.

Deferred: Issue remains open until PR #50 is merged; close #36 after merge.

Follow-up issues: none.

Docs updated: Static OpenAPI contract regenerated in ErsatzTV/wwwroot/openapi/v1.json; no narrative docs change needed because docs/rest-api.md already listed the schedule API shape.

## Done **What was done**: Implemented schedule REST API slice #2c in PR #50. Added `/api/schedules` CRUD endpoints plus schedule item list/add/bulk-replace/delete endpoints, request DTOs for the wire contract, explicit `PlayoutMode` schedule item discriminator, and a `DeleteProgramScheduleItem` MediatR command/handler. Kept controllers thin over MediatR and reused the #46 `ProblemDetails` 404/422 result contract and API-key write filter convention. **Root cause**: n/a — feature slice. **Files changed**: Schedule API controller/request DTOs, schedule command handlers/error mapping, schedule item delete command/handler, controller/API metadata/OpenAPI tests, handler characterization tests, SQLite TPT integration tests, `Startup.cs` OpenAPI enum schema transformer, and regenerated `ErsatzTV/wwwroot/openapi/v1.json`. **Verification**: LSP diagnostics clean on changed C# files. `scripts/update-openapi.sh` passed. `dotnet build ErsatzTV.sln` passed with 0 warnings/errors. `TZ=UTC dotnet test ErsatzTV.sln -v normal` passed. Gitea Actions run #181 for PR #50 completed successfully: Build & test green, EF migration integrity green, PR image job skipped as expected. **Deferred**: Issue remains open until PR #50 is merged; close #36 after merge. **Follow-up issues**: none. **Docs updated**: Static OpenAPI contract regenerated in `ErsatzTV/wwwroot/openapi/v1.json`; no narrative docs change needed because `docs/rest-api.md` already listed the schedule API shape.
Author
Owner

Merged PR #50 into main. CI was green before merge; closing #36.

Merged PR #50 into `main`. CI was green before merge; closing #36.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#36