feat(api): filler preset + watermark editor CRUD; ffmpeg profile round-trip (#159)
Backend plumbing for the SPA transcoding editors (#143 blocker): - FFmpeg profile response DTO round-trip: add NormalizeAudio, NormalizeVideo, PadMode, TargetLoudness, NormalizeColors, ResolutionId (keep Resolution name for compat); DeinterlaceVideo now bool (was bool?). #nullable enable on the DTO. - New GET /api/ffmpeg/hardware-acceleration-kinds wrapping GetSupportedHardwareAccelerationKinds (returns enum names as strings). - Filler preset CRUD: GET-by-id/POST/PUT/DELETE on FillerPresetController with full request/response DTOs; new FillerPresetFullResponseModel + GetFillerPresetByIdForApi. CreateFillerPreset now returns the new id (CreateFillerPresetResult) to match sibling Create commands and enable a 201+Location; updated the one Blazor call site. - Watermark CRUD: GET-by-id/POST/PUT/DELETE on WatermarkController with full DTOs (path+contentType, all 15 fields); new WatermarkFullResponseModel + GetWatermarkByIdForApi. - Startup: register WatermarkLocation/WatermarkSize as OpenAPI string enums (they live in ErsatzTV.FFmpeg.State and were documented as ints, mismatching the Newtonsoft StringEnumConverter runtime serialization). - Tests: full CRUD controller tests for filler + watermark; contract-test entries (404/401/422) for the new mutating endpoints; regenerated v1.json. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ErsatzTV.Application.Filler;
|
||||
using ErsatzTV.Controllers.Api.Requests;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Api.Filler;
|
||||
using ErsatzTV.Extensions;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -16,4 +20,83 @@ public class FillerPresetController(IMediator mediator) : ControllerBase
|
||||
[ProducesResponseType(typeof(List<FillerPresetResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<FillerPresetResponseModel>> GetAll(CancellationToken cancellationToken) =>
|
||||
await mediator.Send(new GetAllFillerPresetsForApi(), 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user