REST API #2a: API foundation + Channels CRUD (pattern-setter) #34

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

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

Slice #2a — API foundation + Channels CRUD. Establishes the conventions every other slice copies.

Foundation

  • Status-code mapping helpers: 201 Created + Location, 200, 204, 404, 422. Add NotFoundError : BaseError in ErsatzTV.Core; mapping returns 404 for it, 422 for other BaseErrors, 201/Location on create, 204 on delete.
  • Request DTO pattern (bound from JSON) → existing MediatR commands. Responses reuse existing *ViewModels.
  • API-key mutation auth filter (new config key Api__WriteKey), applied only to POST/PUT/DELETE on /api/*. Decoupled from the IPTV JWT toggle — must NOT touch JwtHelper.IsEnabled; /iptv/* + all reads untouched (zero Jellyfin/Dispatcharr impact). Enforced only when the key is configured.
  • [EndpointGroupName("general")] so endpoints surface in the existing OpenAPI/Scalar /docs.

Channels

  • POST /api/channels (201+Location) · PUT /api/channels/{id} (200) · DELETE /api/channels/{id} (204) · GET /api/channels/{id} (200/404). GET /api/channels list already exists.
  • Map DTOs → existing CreateChannel / UpdateChannel / DeleteChannel (all return Either<BaseError, _>).
  • Port page-only validations into the handlers (test-before/after): ShowInEpg must be false when !IsEnabled; external-logo-URL format.

Tests (NUnit + Shouldly + NSubstitute, run TZ=UTC)

  • Handler unit: success + 404 (not found) + 422 (validation incl. ported rules + number uniqueness).
  • Controller: status-code / Location / DTO mapping.
  • EF integration (SQLite): create→read→delete.

One branch = one PR; test + migrations green to merge (no model change → migrations trivially green). Idiomatic REST per design doc.

Part of #2 (REST API tracker). Design: `docs/rest-api.md`. **Slice #2a — API foundation + Channels CRUD.** Establishes the conventions every other slice copies. ### Foundation - Status-code mapping helpers: 201 Created + `Location`, 200, 204, 404, 422. Add `NotFoundError : BaseError` in `ErsatzTV.Core`; mapping returns **404** for it, **422** for other `BaseError`s, **201/`Location`** on create, **204** on delete. - Request DTO pattern (bound from JSON) → existing MediatR commands. Responses reuse existing `*ViewModel`s. - **API-key mutation auth filter** (new config key `Api__WriteKey`), applied only to POST/PUT/DELETE on `/api/*`. **Decoupled from the IPTV JWT toggle** — must NOT touch `JwtHelper.IsEnabled`; `/iptv/*` + all reads untouched (zero Jellyfin/Dispatcharr impact). Enforced only when the key is configured. - `[EndpointGroupName("general")]` so endpoints surface in the existing OpenAPI/Scalar `/docs`. ### Channels - `POST /api/channels` (201+Location) · `PUT /api/channels/{id}` (200) · `DELETE /api/channels/{id}` (204) · `GET /api/channels/{id}` (200/404). `GET /api/channels` list already exists. - Map DTOs → existing `CreateChannel` / `UpdateChannel` / `DeleteChannel` (all return `Either<BaseError, _>`). - Port page-only validations into the handlers (test-before/after): `ShowInEpg` must be false when `!IsEnabled`; external-logo-URL format. ### Tests (NUnit + Shouldly + NSubstitute, run `TZ=UTC`) - Handler unit: success + 404 (not found) + 422 (validation incl. ported rules + number uniqueness). - Controller: status-code / `Location` / DTO mapping. - EF integration (SQLite): create→read→delete. One branch = one PR; `test` + `migrations` green to merge (no model change → migrations trivially green). Idiomatic REST per design doc.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#34