feat(api): GET /api/collections/{id}/items (paged) + confirm POST-items 422 guard (#155)

Adds a paged collection-items endpoint reusing LibraryBrowseItemResponseModel
so the SPA lists a manual collection's full contents (all media kinds), replacing
the lossy Lucene name-based preview. Confirms POST /items already returns 422 for
bogus ids (guarded by ValidateMediaItems, fb3f2856); adds endpoint-level coverage.

fixes #155

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 18:26:52 +02:00
co-authored by Claude Opus 4.8
parent 50ae0a7f3b
commit f869dfe87a
14 changed files with 1045 additions and 666 deletions
@@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations;
using ErsatzTV.Application.MediaCollections;
using ErsatzTV.Controllers.Api.Requests;
using ErsatzTV.Core;
using ErsatzTV.Core.Api.LibraryBrowse;
using ErsatzTV.Extensions;
using MediatR;
using Microsoft.AspNetCore.Http;
@@ -32,6 +33,28 @@ public class CollectionController(IMediator mediator) : ControllerBase
return result.ToGetResult();
}
[HttpGet("/api/collections/{id:int}/items", Name = "GetCollectionItems")]
[Tags("Collections")]
[EndpointSummary("Get the items in a manual collection")]
[EndpointDescription("Returns a manual collection's full contents (all media kinds), paged.")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(PagedLibraryBrowseItemsResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetItems(
int id,
[FromQuery] int pageNum = 0,
[FromQuery] int pageSize = 100,
CancellationToken cancellationToken = default)
{
int clampedPageNum = Math.Max(0, pageNum);
int clampedPageSize = Math.Clamp(pageSize, 1, 100);
Either<BaseError, PagedLibraryBrowseItemsResponseModel> result = await mediator.Send(
new GetCollectionItems(id, clampedPageNum, clampedPageSize),
cancellationToken);
return result.ToUpdatedResult();
}
[HttpPost("/api/collections")]
[Tags("Collections")]
[EndpointSummary("Create a collection")]
+79
View File
@@ -2626,6 +2626,85 @@
}
},
"/api/collections/{id}/items": {
"get": {
"tags": [
"Collections"
],
"summary": "Get the items in a manual collection",
"description": "Returns a manual collection's full contents (all media kinds), paged.",
"operationId": "GetCollectionItems",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "pageNum",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 0
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 100
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/PagedLibraryBrowseItemsResponseModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/PagedLibraryBrowseItemsResponseModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/PagedLibraryBrowseItemsResponseModel"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
},
"post": {
"tags": [
"Collections"