Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 10s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m12s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 3m4s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Version every /api route to /api/v1 (251 controller routes + ~24 Location
headers + the scanner callback URL + the Startup request-log literal),
uniform across the machine API, auth, scanner and scripted-build surfaces.
Add ApiVersionRewriteMiddleware: a legacy unversioned /api/* request is
rewritten (NOT redirected) to /api/v1/* in-pipeline — method, body, auth
headers and query survive — carrying RFC 8594 Deprecation/Sunset headers,
so curl / the future MCP server / bookmarks keep working. An already-
versioned path passes through; a future /api/v2 is never forced to v1.
Standardize the route convention (leading-slash absolute route per method,
no class-[Route] — except the two Scanner/Scripted controllers whose ~all
actions share a parametrized {id} prefix), enforced by ApiRouteVersioningTests
(^/api/v\d+/ over the whole Controllers.Api surface; browser-nav
/auth/oidc/login is out of scope).
Regenerate v1.json (160 paths, all /api/v1)/endpoint-index/v1.d.ts; sweep 945
SPA request literals + the test mocks (regex + positional URL parsers). /api/v1
is additive-only after freeze; the legacy-rewrite shim sunsets in ~2 releases
(owner decision) with removal tracked as a Phase-3 follow-up.
Docs: decisions.md 2026-07-13, api-conventions §1/§9, rest-api/spa-conventions/
blazor-route-parity/e2e-local/domain-model.
fixes #286
refs #197
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
66 lines
3.0 KiB
C#
66 lines
3.0 KiB
C#
using ErsatzTV.Application.LibraryBrowse;
|
|
using ErsatzTV.Core.Api.LibraryBrowse;
|
|
using ErsatzTV.Core.Api.Search;
|
|
using MediatR;
|
|
|
|
namespace ErsatzTV.Application.Search;
|
|
|
|
// Fans out to the shared library-browse query once per media kind (mirroring the legacy Search.razor page,
|
|
// which sends one `type:{kind} AND ({query})` query per kind). Reusing GetLibraryBrowseItems keeps hydration,
|
|
// artwork resolution and the response shape identical to /api/v1/library/browse. Raw Lucene queries pass through
|
|
// unchanged, so state filters such as `state:FileNotFound` (the Trash screen) work here too.
|
|
public class GetSearchResultsHandler(IMediator mediator)
|
|
: IRequestHandler<GetSearchResults, SearchResultsResponseModel>
|
|
{
|
|
public async Task<SearchResultsResponseModel> Handle(
|
|
GetSearchResults request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
async Task<SearchResultGroupResponseModel> ForKind(LibraryBrowseMediaType kind)
|
|
{
|
|
PagedLibraryBrowseItemsResponseModel paged = await mediator.Send(
|
|
new GetLibraryBrowseItems(request.Query, null, kind, request.PageNum, request.PageSize),
|
|
cancellationToken);
|
|
return new SearchResultGroupResponseModel(paged.TotalCount, paged.Page);
|
|
}
|
|
|
|
// Each ForKind call sends through IMediator to GetLibraryBrowseItemsHandler, which creates its
|
|
// own TvContext per invocation via IDbContextFactory<TvContext> (never shares one across calls),
|
|
// so these are safe to run concurrently.
|
|
Task<SearchResultGroupResponseModel> movies = ForKind(LibraryBrowseMediaType.Movie);
|
|
Task<SearchResultGroupResponseModel> shows = ForKind(LibraryBrowseMediaType.TelevisionShow);
|
|
Task<SearchResultGroupResponseModel> seasons = ForKind(LibraryBrowseMediaType.TelevisionSeason);
|
|
Task<SearchResultGroupResponseModel> artists = ForKind(LibraryBrowseMediaType.Artist);
|
|
Task<SearchResultGroupResponseModel> episodes = ForKind(LibraryBrowseMediaType.Episode);
|
|
Task<SearchResultGroupResponseModel> musicVideos = ForKind(LibraryBrowseMediaType.MusicVideo);
|
|
Task<SearchResultGroupResponseModel> songs = ForKind(LibraryBrowseMediaType.Song);
|
|
Task<SearchResultGroupResponseModel> otherVideos = ForKind(LibraryBrowseMediaType.OtherVideo);
|
|
Task<SearchResultGroupResponseModel> images = ForKind(LibraryBrowseMediaType.Image);
|
|
Task<SearchResultGroupResponseModel> remoteStreams = ForKind(LibraryBrowseMediaType.RemoteStream);
|
|
|
|
await Task.WhenAll(
|
|
movies,
|
|
shows,
|
|
seasons,
|
|
artists,
|
|
episodes,
|
|
musicVideos,
|
|
songs,
|
|
otherVideos,
|
|
images,
|
|
remoteStreams);
|
|
|
|
return new SearchResultsResponseModel(
|
|
movies.Result,
|
|
shows.Result,
|
|
seasons.Result,
|
|
artists.Result,
|
|
episodes.Result,
|
|
musicVideos.Result,
|
|
songs.Result,
|
|
otherVideos.Result,
|
|
images.Result,
|
|
remoteStreams.Result);
|
|
}
|
|
}
|