feat(web+api): scheduling templates + block/template copy (#144 S2, #162) #173

Merged
timothy merged 6 commits from feat/144-s2-templates into main 2026-07-07 19:00:45 +02:00
Owner

Slice S2 of the #162 scheduling REST plan (parity issue #144): Templates + Template Groups, plus the S1-deferred block copy.

API (new TemplateController, mirrors BlockController)

  • GET/POST /api/templates/groups, DELETE /api/templates/groups/{id} (cascade documented)
  • GET /api/templates (optional ?templateGroupId= filter), GET/POST/DELETE /api/templates[/{id}]
  • GET /api/templates/{id}/items (404-guarded, startTime-sorted, carries blockName + minutes for end-time display)
  • PUT /api/templates/{id} — full replace via ReplaceTemplateItems (server-side overlap validation)
  • POST /api/templates/{id}/copy + POST /api/blocks/{id}/copy (CopyBlock deep-copies items+watermarks+graphics — verified)
  • Root-cause fixes in Application handlers (same latent-500 class as S1): CreateTemplateHandler now validates group existence; ReplaceTemplateItemsHandler now 422s on unknown blockId (was KeyNotFoundException → 500, confirmed live) and rejects midnight-crossing items (were accepted then silently dropped/deleted by the items query's invalid-item filter).

SPA

  • web/src/api/templates.ts + tests; /app/templates grouped list (create/copy/delete dialogs) + /app/templates/{id} editor: add-content row (block-group → block → 5-min start-time select), time-sorted items table with computed end times, client-side overlap + midnight-crossing warnings (Save disabled), block picker excludes the synthesized "(none)" placeholder rows. Deviation from Blazor stated in-code: table editor instead of the drag calendar (server stays authoritative).

Verification

  • ErsatzTV.Tests 692 green; Core.Tests 493 green; web 253 green; lint/tsc/build clean.
  • Live E2E: full API matrix incl. filter, copies, cascade delete, overlap 422, group-existence 422 (not 500); browser flows: create/copy/delete dialogs, editor round-trip with persistence + sorted display, client-side overlap warning. E2E found the blockId-500 (fixed above).
  • Adversarial review: 1 must-fix + 1 should-fix applied (above); nits consolidated into #172.

Part of #144 / #162 (slice S2 — do not auto-close).

🤖 Generated with Claude Code

Slice S2 of the #162 scheduling REST plan (parity issue #144): Templates + Template Groups, plus the S1-deferred block copy. **API** (new `TemplateController`, mirrors BlockController) - `GET/POST /api/templates/groups`, `DELETE /api/templates/groups/{id}` (cascade documented) - `GET /api/templates` (optional `?templateGroupId=` filter), `GET/POST/DELETE /api/templates[/{id}]` - `GET /api/templates/{id}/items` (404-guarded, startTime-sorted, carries blockName + minutes for end-time display) - `PUT /api/templates/{id}` — full replace via ReplaceTemplateItems (server-side overlap validation) - `POST /api/templates/{id}/copy` + `POST /api/blocks/{id}/copy` (CopyBlock deep-copies items+watermarks+graphics — verified) - Root-cause fixes in Application handlers (same latent-500 class as S1): `CreateTemplateHandler` now validates group existence; `ReplaceTemplateItemsHandler` now 422s on unknown blockId (was KeyNotFoundException → 500, confirmed live) and rejects midnight-crossing items (were accepted then silently dropped/deleted by the items query's invalid-item filter). **SPA** - `web/src/api/templates.ts` + tests; `/app/templates` grouped list (create/copy/delete dialogs) + `/app/templates/{id}` editor: add-content row (block-group → block → 5-min start-time select), time-sorted items table with computed end times, client-side overlap + midnight-crossing warnings (Save disabled), block picker excludes the synthesized "(none)" placeholder rows. Deviation from Blazor stated in-code: table editor instead of the drag calendar (server stays authoritative). **Verification** - ErsatzTV.Tests 692 green; Core.Tests 493 green; web 253 green; lint/tsc/build clean. - Live E2E: full API matrix incl. filter, copies, cascade delete, overlap 422, group-existence 422 (not 500); browser flows: create/copy/delete dialogs, editor round-trip with persistence + sorted display, client-side overlap warning. E2E found the blockId-500 (fixed above). - Adversarial review: 1 must-fix + 1 should-fix applied (above); nits consolidated into #172. Part of #144 / #162 (slice S2 — do not auto-close). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timothy added 6 commits 2026-07-07 18:55:11 +02:00
Adds TemplateController mirroring BlockController: groups CRUD, template
CRUD, item replace (PUT full-replace via ReplaceTemplateItems), and a
copy endpoint. Also wires the missing POST /api/blocks/{id}/copy since
CopyBlock's CQRS shape is directly analogous to CopyTemplate.

Fixes CreateTemplateHandler to validate the target template group exists
before insert (previously an unhandled FK violation -> 500), matching the
CreateBlockHandler fix (1e34e00e) for the same class of bug.

New DTOs in ErsatzTV.Core/Api/Scheduling; TimeSpan start times serialize
the same way as PlayoutResponseModel.DailyRebuildTime.

#144 S2 (#162)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
#144 S2 (#162)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds a ChicoryTV Templates screen under /app/templates: grouped template
list with group/template create, copy, and delete, and a
/app/templates/{id} editor (name, add-content row that picks a block
group -> block -> five-minute start time, a time-sorted item table with
remove, and a client-side overlap warning that mirrors
ReplaceTemplateItemsHandler's server-side check before allowing save).

Deviates from the Blazor TemplateEditor.razor's drag-to-place day
calendar: uses a plain sorted table + picker row instead, per the S2
spec (parity, not a pixel port).

Adds web/src/api/templates.ts client + copyBlock to blocks.ts (S1 left
the block-copy endpoint unwired; CopyBlock's CQRS shape is identical to
CopyTemplate so it rides along here), plus regenerated v1.d.ts types.

#144 S2 (#162)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PUT /api/templates/{id} with an unknown blockId threw KeyNotFoundException
(HTTP 500) because the dictionary indexer assumed every referenced block
had been loaded. Validate all blockIds exist before building the overlap
list and return a 422 with "[BlockId] {id} does not exist." on failure,
matching ReplaceBlockItemsHandler's message convention.

Also reject items whose start time + block duration crosses midnight
(> 24:00). Previously these were silently accepted by PUT, then dropped
by GetTemplateItemsHandler's end-of-day filter on every subsequent GET,
so a saved item would vanish and be deleted on the next save.
fix(templates-screen): exclude placeholder blocks, warn on midnight crossing
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 4m24s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m28s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
d48e48f1be
GET /api/blocks emits a synthesized negative-id "(none)" row per empty
block group; the block picker was including it as a selectable option.
Filter to b.id > 0, mirroring the backend's real block ids.

Also mirror ReplaceTemplateItemsHandler's new end-of-day validation on
the client: flag an item whose start time + block duration crosses
midnight and disable Save, same as the existing overlap-warning path.

Adds coverage: block picker excludes negative-id rows; validate() flags
a midnight-crossing item.
timothy merged commit 86f280f9d0 into main 2026-07-07 19:00:45 +02:00
timothy deleted branch feat/144-s2-templates 2026-07-07 19:00:45 +02:00
Sign in to join this conversation.