Adds DecoController (groups + decos CRUD + full-state PUT), playlist and
artist/multi-collection search picker wrappers, a PlaylistController for the
break-content playlist cascade, and PUT /api/playouts/{id}/deco. Fixes the
CreateDecoHandler missing deco-group existence check (FK 500 -> 422), matching
the CreateBlock/CreateTemplate precedent. ReplaceDecoRequest.ToCommand rejects
Merge on the non-mergeable sections (422).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
138 lines
6.4 KiB
C#
138 lines
6.4 KiB
C#
using ErsatzTV.Application.MediaCollections;
|
|
using ErsatzTV.Application.MediaItems;
|
|
using ErsatzTV.Application.Search;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Api.Scheduling;
|
|
using ErsatzTV.Core.Api.Search;
|
|
using ErsatzTV.Extensions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
public class SearchController(IMediator mediator) : ControllerBase
|
|
{
|
|
private const int MaxPageSize = 100;
|
|
|
|
[HttpGet("/api/search", Name = "Search")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search library items across all media kinds")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(SearchResultsResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> Search(
|
|
[FromQuery] string query = "",
|
|
[FromQuery] int pageSize = 50,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(query))
|
|
{
|
|
return BaseError.New("A non-empty query is required").ToErrorResult();
|
|
}
|
|
|
|
int clampedPageSize = Math.Clamp(pageSize, 1, MaxPageSize);
|
|
SearchResultsResponseModel result = await mediator.Send(
|
|
new GetSearchResults(query, clampedPageSize),
|
|
cancellationToken);
|
|
return new OkObjectResult(result);
|
|
}
|
|
|
|
[HttpGet("/api/search/collections", Name = "SearchCollections")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search collections by name")]
|
|
[EndpointDescription("Returns matching collections as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchCollections(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<MediaCollectionViewModel> results = await mediator.Send(
|
|
new SearchCollections(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(c => new SchedulingPickerOptionResponseModel(c.Id, c.Name)).ToList();
|
|
}
|
|
|
|
[HttpGet("/api/search/television-shows", Name = "SearchTelevisionShows")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search television shows by name")]
|
|
[EndpointDescription("Returns matching television shows as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchTelevisionShows(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<NamedMediaItemViewModel> results = await mediator.Send(
|
|
new SearchTelevisionShows(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(s => new SchedulingPickerOptionResponseModel(s.MediaItemId, s.Name)).ToList();
|
|
}
|
|
|
|
[HttpGet("/api/search/television-seasons", Name = "SearchTelevisionSeasons")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search television seasons by name")]
|
|
[EndpointDescription("Returns matching television seasons as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchTelevisionSeasons(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<NamedMediaItemViewModel> results = await mediator.Send(
|
|
new SearchTelevisionSeasons(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(s => new SchedulingPickerOptionResponseModel(s.MediaItemId, s.Name)).ToList();
|
|
}
|
|
|
|
[HttpGet("/api/search/smart-collections", Name = "SearchSmartCollections")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search smart collections by name")]
|
|
[EndpointDescription("Returns matching smart collections as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchSmartCollections(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<SmartCollectionViewModel> results = await mediator.Send(
|
|
new SearchSmartCollections(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(c => new SchedulingPickerOptionResponseModel(c.Id, c.Name)).ToList();
|
|
}
|
|
|
|
[HttpGet("/api/search/artists", Name = "SearchArtists")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search artists by name")]
|
|
[EndpointDescription("Returns matching artists as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchArtists(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<NamedMediaItemViewModel> results = await mediator.Send(
|
|
new SearchArtists(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(a => new SchedulingPickerOptionResponseModel(a.MediaItemId, a.Name)).ToList();
|
|
}
|
|
|
|
[HttpGet("/api/search/multi-collections", Name = "SearchMultiCollections")]
|
|
[Tags("Search")]
|
|
[EndpointSummary("Search multi collections by name")]
|
|
[EndpointDescription("Returns matching multi collections as {id, name} options for scheduling editors.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<SchedulingPickerOptionResponseModel>> SearchMultiCollections(
|
|
[FromQuery] string query = "",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
List<MultiCollectionViewModel> results = await mediator.Send(
|
|
new SearchMultiCollections(query ?? string.Empty),
|
|
cancellationToken);
|
|
return results.Map(c => new SchedulingPickerOptionResponseModel(c.Id, c.Name)).ToList();
|
|
}
|
|
}
|