using ErsatzTV.Application.Graphics; using ErsatzTV.Core.Api.Graphics; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace ErsatzTV.Controllers.Api; [ApiController] public class GraphicsElementController(IMediator mediator) : ControllerBase { [HttpGet("/api/v1/graphics-elements", Name = "GetGraphicsElements")] [Tags("Graphics Elements")] [EndpointSummary("Get all graphics elements")] [EndpointDescription("Returns all graphics elements.")] [EndpointGroupName("general")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task> GetAll(CancellationToken cancellationToken) => await mediator.Send(new GetAllGraphicsElementsForApi(), cancellationToken); [HttpPost("/api/v1/graphics-elements/refresh", Name = "RefreshGraphicsElements")] [Tags("Graphics Elements")] [EndpointSummary("Re-sync graphics elements from disk")] [EndpointDescription( "Re-syncs the on-disk graphics element definitions into the database (matching the legacy Blazor " + "behavior) so newly added files appear.")] [EndpointGroupName("general")] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Refresh(CancellationToken cancellationToken) { await mediator.Send(new RefreshGraphicsElements(), cancellationToken); return NoContent(); } }