Backend: media sources + libraries read model (GET /api/media-sources) #103

Closed
opened 2026-07-02 19:44:02 +02:00 by timothy · 1 comment
Owner

From the ChicoryTV plan audit (epic #59, 2026-07-02).

No GET endpoint lists media sources or libraries — the only library routes are scan POSTs, and no DTOs exist under ErsatzTV.Core/Api/ for them. The Libraries screen (#88) has nothing to render. The data exists internally: GetConfiguredLibraries, GetAllPlexMediaSources/GetAllJellyfinMediaSources/GetAllEmbyMediaSources, CountMediaItemsByLibrary.

Scope

  • Add GET /api/media-sources: sources grouped by kind (Local/Plex/Jellyfin/Emby) with name + connection address/path, each with child libraries {id, name, mediaKind, lastScan}.
  • Include per-library item counts via a single GROUP BY query (do NOT loop CountMediaItemsByLibrary per library — N+1).
  • New DTOs under ErsatzTV.Core/Api/; regenerate OpenAPI + SPA types.
  • Caveat: LocalMediaSource has no Name — synthesize a label (e.g. "Local").

Consumers: #88 (source cards + library rows + counts, hard block), #65 (library filter dropdown), #89 (library filter chips), Dashboard follow-up "Libraries" tile. Build once, share.

Hard-blocks #88. Effort: S–M (wrapper + one aggregate query).

From the ChicoryTV plan audit (epic #59, 2026-07-02). No GET endpoint lists media sources or libraries — the only library routes are scan POSTs, and no DTOs exist under `ErsatzTV.Core/Api/` for them. The Libraries screen (#88) has nothing to render. The data exists internally: `GetConfiguredLibraries`, `GetAllPlexMediaSources`/`GetAllJellyfinMediaSources`/`GetAllEmbyMediaSources`, `CountMediaItemsByLibrary`. **Scope** - Add `GET /api/media-sources`: sources grouped by kind (Local/Plex/Jellyfin/Emby) with name + connection address/path, each with child libraries `{id, name, mediaKind, lastScan}`. - Include per-library item counts via a single GROUP BY query (do NOT loop `CountMediaItemsByLibrary` per library — N+1). - New DTOs under `ErsatzTV.Core/Api/`; regenerate OpenAPI + SPA types. - Caveat: `LocalMediaSource` has no Name — synthesize a label (e.g. "Local"). **Consumers:** #88 (source cards + library rows + counts, hard block), #65 (library filter dropdown), #89 (library filter chips), Dashboard follow-up "Libraries" tile. Build once, share. **Hard-blocks #88.** Effort: S–M (wrapper + one aggregate query).
timothy added the enhancementapi labels 2026-07-02 19:44:02 +02:00
timothy added a new dependency 2026-07-02 19:44:15 +02:00
Author
Owner

Done

What was done: Opened PR #115 with GET /api/media-sources. The endpoint returns media sources grouped by kind/source with child libraries containing id, name, mediaKind, lastScan, and itemCount. Local sources synthesize Local as the source name. The item counts come from one grouped SQL aggregate over MediaItem + LibraryPath, not one query per library.

Root cause: n/a - feature gap for the ChicoryTV Libraries screen.

Files changed: API DTOs under ErsatzTV.Core/Api/MediaSources, MediatR query/handler under ErsatzTV.Application/MediaSources, MediaSourcesController, focused handler/controller tests, and regenerated ErsatzTV/wwwroot/openapi/v1.json.

Verification: dotnet build ErsatzTV.sln passed with existing NU1903 advisory warnings. TZ=UTC dotnet test ErsatzTV.Tests/ErsatzTV.Tests.csproj -v minimal passed: 285 passed, 0 failed. OpenAPI generation passed via dotnet build -t:GenerateOpenApiDocuments --no-restore -m:1 /nodeReuse:false; the plain script target hung once and was cancelled before the constrained equivalent completed.

Deferred: Issue closure is deferred until PR #115 is reviewed and merged; the PR body includes Fixes #103.

Follow-up issues: none.

Docs updated: OpenAPI v1.json regenerated; no separate docs changes needed.

## Done **What was done**: Opened PR #115 with `GET /api/media-sources`. The endpoint returns media sources grouped by kind/source with child libraries containing `id`, `name`, `mediaKind`, `lastScan`, and `itemCount`. Local sources synthesize `Local` as the source name. The item counts come from one grouped SQL aggregate over `MediaItem` + `LibraryPath`, not one query per library. **Root cause**: n/a - feature gap for the ChicoryTV Libraries screen. **Files changed**: API DTOs under `ErsatzTV.Core/Api/MediaSources`, MediatR query/handler under `ErsatzTV.Application/MediaSources`, `MediaSourcesController`, focused handler/controller tests, and regenerated `ErsatzTV/wwwroot/openapi/v1.json`. **Verification**: `dotnet build ErsatzTV.sln` passed with existing NU1903 advisory warnings. `TZ=UTC dotnet test ErsatzTV.Tests/ErsatzTV.Tests.csproj -v minimal` passed: 285 passed, 0 failed. OpenAPI generation passed via `dotnet build -t:GenerateOpenApiDocuments --no-restore -m:1 /nodeReuse:false`; the plain script target hung once and was cancelled before the constrained equivalent completed. **Deferred**: Issue closure is deferred until PR #115 is reviewed and merged; the PR body includes `Fixes #103`. **Follow-up issues**: none. **Docs updated**: OpenAPI `v1.json` regenerated; no separate docs changes needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: timothy/ersatztv#103