Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m11s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 12s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m49s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
POST /api/libraries/{id}/scan-show resolved the target show via
GetShowIdByTitle, an EF.Functions.Like "%title%" substring match with
no OrderBy - non-deterministic under duplicate/overlapping titles and
capable of scanning the wrong show. The Blazor UI never had this bug
(it always passed the exact show id); this endpoint shipped days ago
in PR #216 with no external consumers, so the contract break is safe.
BREAKING CHANGE: ScanShowRequest now takes `showId: int` instead of
`showTitle: string`. Replaced ITelevisionRepository.GetShowIdByTitle
with GetShowTitle(libraryId, showId), which also enforces the show
belongs to the given library. LibrariesController.ScanShow now returns
a genuine 404 ProblemDetails (via ApiResults.NotFoundProblem, the
established pre-check pattern from TemplateController.DeleteGroup)
when the show id doesn't exist in that library, then queues
QueueShowScanByLibraryId with the DB-resolved title.
SPA: libraries.ts ScanShowParams.showId replaces showTitle;
MediaDetailScreen.tsx passes show.id. Extended
ApiErrorResponseMetadataTests and OpenApiErrorResponseContractTests
with the new 404 contract for ScanShow. Regenerated v1.json / v1.d.ts
via scripts/update-openapi.sh + npm run generate:api.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
2.2 KiB
C#
53 lines
2.2 KiB
C#
using ErsatzTV.Application.Libraries;
|
|
using ErsatzTV.Core.Api.Libraries;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using ErsatzTV.Extensions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
[EndpointGroupName("general")]
|
|
public class LibrariesController(ITelevisionRepository televisionRepository, IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpGet("/api/libraries/scan-status", Name = "GetLibraryScanStatus")]
|
|
[Tags("Libraries")]
|
|
[EndpointSummary("Get active library scan status")]
|
|
[ProducesResponseType(typeof(List<LibraryScanStatusResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<LibraryScanStatusResponseModel>> GetScanStatus(CancellationToken cancellationToken) =>
|
|
await mediator.Send(new GetLibraryScanStatus(), cancellationToken);
|
|
|
|
[HttpPost("/api/libraries/{id:int}/scan")]
|
|
[Tags("Libraries")]
|
|
[EndpointSummary("Scan library")]
|
|
public async Task<IActionResult> ScanLibrary(int id) =>
|
|
await mediator.Send(new QueueLibraryScanByLibraryId(id))
|
|
? new OkResult()
|
|
: new NotFoundResult();
|
|
|
|
[HttpPost("/api/libraries/{id:int}/scan-show")]
|
|
[Tags("Libraries")]
|
|
[EndpointSummary("Scan show")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> ScanShow(int id, [FromBody] ScanShowRequest request)
|
|
{
|
|
Option<string> maybeTitle = await televisionRepository.GetShowTitle(id, request.ShowId);
|
|
foreach (string title in maybeTitle)
|
|
{
|
|
bool result = await mediator.Send(new QueueShowScanByLibraryId(id, request.ShowId, title, request.DeepScan));
|
|
|
|
return result
|
|
? new OkResult()
|
|
: new BadRequestObjectResult(new { error = "Unable to queue show scan. Library may not exist, may not support single show scanning, or may already be scanning." });
|
|
}
|
|
|
|
return ApiResults.NotFoundProblem($"Show {request.ShowId} does not exist in library {id}.");
|
|
}
|
|
}
|
|
|
|
public record ScanShowRequest(int ShowId, bool DeepScan = false);
|