Files
ersatztv/ErsatzTV/Controllers/Api/ShowsController.cs
T
timothyandClaude Fable 5 cd31c755bb feat(api): media detail + info + image-folder endpoints (#141/#161)
Add REST endpoints backing the SPA media detail pages and image browser:

- GET /api/movies/{id}, /api/shows/{id}, /api/seasons/{id}, /api/artists/{id}
  wrapping the existing detail queries; 404 on None.
- GET /api/media-items/{id}/info wrapping GetMediaItemInfo; UnableToLocateMediaItem
  -> 404, other errors -> 422.
- GET /api/images/folders?parentId= and PUT /api/images/folders/{id}/duration
  (validates null-or-positive -> 400; existence guard via new ImageFolderExists
  query -> 404).
- Extend GetLibraryBrowseItems parentId drill-in to Episode (episodes of a season,
  episode-number order) and MusicVideo (an artist's music videos, album/track order),
  alongside the existing TelevisionSeason branch.

Response DTOs live in ErsatzTV.Core/Api/* and never expose Application VMs. Artwork
values are rooted for the SPA via a shared ErsatzTV.Core/Api/ApiArtwork helper
(mirrors the #180/#181 browse-handler logic; handles jellyfin/emby proxy prefixes,
http passthrough, empty). Regenerated OpenAPI v1.json + web v1.d.ts. New controllers
registered in ApiControllerSecurityTests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 22:43:47 +02:00

46 lines
1.7 KiB
C#

using ErsatzTV.Application.Television;
using ErsatzTV.Core.Api;
using ErsatzTV.Core.Api.Media;
using ErsatzTV.Core.Api.Television;
using ErsatzTV.Core.Domain;
using ErsatzTV.Extensions;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ErsatzTV.Controllers.Api;
[ApiController]
public class ShowsController(IMediator mediator) : ControllerBase
{
[HttpGet("/api/shows/{id:int}", Name = "GetShowById")]
[Tags("Television")]
[EndpointSummary("Get a television show by id")]
[EndpointGroupName("general")]
[ProducesResponseType(typeof(ShowDetailResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
{
Option<TelevisionShowViewModel> result = await mediator.Send(new GetTelevisionShowById(id), cancellationToken);
return result.Map(Project).ToGetResult();
}
private static ShowDetailResponseModel Project(TelevisionShowViewModel vm) =>
new(
vm.Id,
vm.LibraryId,
vm.MediaSourceKind,
vm.Title,
string.IsNullOrWhiteSpace(vm.Year) ? null : vm.Year,
string.IsNullOrWhiteSpace(vm.Plot) ? null : vm.Plot,
ApiArtwork.Root(vm.Poster, ArtworkKind.Poster),
ApiArtwork.Root(vm.FanArt, ArtworkKind.FanArt),
vm.Genres,
vm.Tags,
vm.Studios,
vm.Networks,
vm.ContentRatings,
vm.Languages.Map(c => c.EnglishName).ToList(),
vm.Actors.Map(a => new ActorResponseModel(a.Id, a.Name, a.Role, ApiArtwork.Root(a.Thumb, ArtworkKind.Thumbnail))).ToList());
}