Task A (#126): new non-polymorphic ScheduleItemResponseModel / ScheduleItemsResponseModel in Core/Api/Scheduling, plus shared NamedIdResponseModel. ScheduleItemResponseMapper flattens the One/Flood/Multiple/Duration VM hierarchy. ScheduleController GET/POST/PUT items now return the flat DTOs. Task B: GET /api/languages (LanguagesController + LanguageCodeResponseModel); GET /api/channels/music-video-credits-templates and GET /api/channels/stream-selectors; FillerKind added to FillerPresetResponseModel with optional ?fillerKind= filter on GET /api/filler-presets. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
107 lines
5.1 KiB
C#
107 lines
5.1 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using ErsatzTV.Application.Filler;
|
|
using ErsatzTV.Controllers.Api.Requests;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Api.Filler;
|
|
using ErsatzTV.Core.Domain.Filler;
|
|
using ErsatzTV.Extensions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
public class FillerPresetController(IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpGet("/api/filler-presets", Name = "GetFillerPresets")]
|
|
[Tags("Filler Presets")]
|
|
[EndpointSummary("Get all filler presets")]
|
|
[EndpointDescription("Optionally filter to a single filler kind via the fillerKind query parameter.")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(List<FillerPresetResponseModel>), StatusCodes.Status200OK)]
|
|
public async Task<List<FillerPresetResponseModel>> GetAll(
|
|
[FromQuery] FillerKind? fillerKind,
|
|
CancellationToken cancellationToken) =>
|
|
await mediator.Send(new GetAllFillerPresetsForApi(fillerKind), cancellationToken);
|
|
|
|
[HttpGet("/api/filler-presets/{id:int}", Name = "GetFillerPresetById")]
|
|
[Tags("Filler Presets")]
|
|
[EndpointSummary("Get a filler preset by id")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FillerPresetFullResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
|
|
{
|
|
Option<FillerPresetFullResponseModel> result =
|
|
await mediator.Send(new GetFillerPresetByIdForApi(id), cancellationToken);
|
|
return result.ToGetResult();
|
|
}
|
|
|
|
[HttpPost("/api/filler-presets", Name = "CreateFillerPreset")]
|
|
[Tags("Filler Presets")]
|
|
[EndpointSummary("Create a filler preset")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FillerPresetFullResponseModel), StatusCodes.Status201Created)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> Create(
|
|
[Required] [FromBody] CreateFillerPresetRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, CreateFillerPresetResult> result =
|
|
await mediator.Send(request.ToCommand(), cancellationToken);
|
|
return await result.Match(
|
|
Left: error => Task.FromResult(error.ToErrorResult()),
|
|
Right: async created =>
|
|
{
|
|
Option<FillerPresetFullResponseModel> fillerPreset =
|
|
await mediator.Send(new GetFillerPresetByIdForApi(created.FillerPresetId), cancellationToken);
|
|
return fillerPreset.Match(
|
|
Some: vm => (IActionResult)new CreatedResult($"/api/filler-presets/{vm.Id}", vm),
|
|
None: () => ApiResults.NotFoundProblem());
|
|
});
|
|
}
|
|
|
|
[HttpPut("/api/filler-presets/{id:int}", Name = "UpdateFillerPreset")]
|
|
[Tags("Filler Presets")]
|
|
[EndpointSummary("Update a filler preset")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(typeof(FillerPresetFullResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> Update(
|
|
int id,
|
|
[Required] [FromBody] UpdateFillerPresetRequest request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, Unit> result = await mediator.Send(request.ToCommand(id), cancellationToken);
|
|
return await result.Match(
|
|
Left: error => Task.FromResult(error.ToErrorResult()),
|
|
Right: async _ =>
|
|
{
|
|
Option<FillerPresetFullResponseModel> fillerPreset =
|
|
await mediator.Send(new GetFillerPresetByIdForApi(id), cancellationToken);
|
|
return fillerPreset.Match(
|
|
Some: vm => (IActionResult)new OkObjectResult(vm),
|
|
None: () => ApiResults.NotFoundProblem());
|
|
});
|
|
}
|
|
|
|
[HttpDelete("/api/filler-presets/{id:int}", Name = "DeleteFillerPreset")]
|
|
[Tags("Filler Presets")]
|
|
[EndpointSummary("Delete a filler preset")]
|
|
[EndpointGroupName("general")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
|
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
|
|
{
|
|
Either<BaseError, Unit> result = await mediator.Send(new DeleteFillerPreset(id), cancellationToken);
|
|
return result.ToDeletedResult();
|
|
}
|
|
}
|