api changes to support etvcli (#2519)

This commit is contained in:
Jason Dove
2025-10-12 10:13:30 -05:00
committed by GitHub
parent bf4182f115
commit 48e7c85f7b
17 changed files with 421 additions and 46 deletions
@@ -14,7 +14,7 @@ namespace ErsatzTV.Controllers.Api;
public class ChannelController(ChannelWriter<IBackgroundServiceRequest> workerChannel, IMediator mediator)
{
[HttpGet("/api/channels")]
[V2ApiActionFilter]
[EndpointGroupName("general")]
public async Task<List<ChannelResponseModel>> GetAll() => await mediator.Send(new GetAllChannelsForApi());
[HttpPost("/api/channels/{channelNumber}/playout/reset")]
@@ -10,30 +10,26 @@ namespace ErsatzTV.Controllers.Api;
[ApiController]
[V2ApiActionFilter]
public class FFmpegProfileController
public class FFmpegProfileController(IMediator mediator)
{
private readonly IMediator _mediator;
public FFmpegProfileController(IMediator mediator) => _mediator = mediator;
[HttpGet("/api/ffmpeg/profiles")]
public async Task<List<FFmpegProfileResponseModel>> GetAll() =>
await _mediator.Send(new GetAllFFmpegProfilesForApi());
await mediator.Send(new GetAllFFmpegProfilesForApi());
[HttpPost("/api/ffmpeg/profiles/new")]
public async Task<Either<BaseError, CreateFFmpegProfileResult>> AddOne(
[Required] [FromBody]
CreateFFmpegProfile request) => await _mediator.Send(request);
CreateFFmpegProfile request) => await mediator.Send(request);
[HttpPut("/api/ffmpeg/profiles/update")]
public async Task<Either<BaseError, UpdateFFmpegProfileResult>> UpdateOne(
[Required] [FromBody]
UpdateFFmpegProfile request) => await _mediator.Send(request);
UpdateFFmpegProfile request) => await mediator.Send(request);
[HttpGet("/api/ffmpeg/profiles/{id:int}")]
public async Task<Option<FFmpegFullProfileResponseModel>> GetOne(int id) =>
await _mediator.Send(new GetFFmpegFullProfileByIdForApi(id));
await mediator.Send(new GetFFmpegFullProfileByIdForApi(id));
[HttpDelete("/api/ffmpeg/delete/{id:int}")]
public async Task DeleteProfileAsync(int id) => await _mediator.Send(new DeleteFFmpegProfile(id));
public async Task DeleteProfileAsync(int id) => await mediator.Send(new DeleteFFmpegProfile(id));
}
@@ -0,0 +1,43 @@
using System.ComponentModel.DataAnnotations;
using ErsatzTV.Application.MediaCollections;
using ErsatzTV.Core;
using ErsatzTV.Core.Api.SmartCollections;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace ErsatzTV.Controllers.Api;
[ApiController]
[EndpointGroupName("general")]
public class SmartCollectionController(IMediator mediator) : ControllerBase
{
[HttpGet("/api/collections/smart", Name="GetSmartCollections")]
public async Task<List<SmartCollectionResponseModel>> GetAll() =>
await mediator.Send(new GetAllSmartCollectionsForApi());
[HttpPost("/api/collections/smart/new", Name = "CreateSmartCollection")]
public async Task<IActionResult> AddOne(
[Required] [FromBody]
CreateSmartCollection request)
{
Either<BaseError, CreateSmartCollectionResult> result =
await mediator.Send(request).MapT(r => new CreateSmartCollectionResult(r.Id));
return result.Match<IActionResult>(Ok, error => Problem(error.ToString()));
}
[HttpPut("/api/collections/smart/update", Name="UpdateSmartCollection")]
public async Task<IActionResult> UpdateOne(
[Required] [FromBody]
UpdateSmartCollection request)
{
Either<BaseError, UpdateSmartCollectionResult> result = await mediator.Send(request);
return result.Match<IActionResult>(Ok, error => Problem(error.ToString()));
}
[HttpDelete("/api/collections/smart/delete/{id:int}", Name="DeleteSmartCollection")]
public async Task<IActionResult> DeleteSmartCollection(int id)
{
Either<BaseError, Unit> result = await mediator.Send(new DeleteSmartCollection(id));
return result.Match<IActionResult>(_ => Ok(), error => Problem(error.ToString()));
}
}
+10 -6
View File
@@ -7,15 +7,19 @@ namespace ErsatzTV.Controllers.Api;
[EndpointGroupName("general")]
public class VersionController
{
private static readonly string Version;
private static readonly CombinedVersion Version;
static VersionController() =>
Version = Assembly.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion ?? "unknown";
Version = new CombinedVersion(
1,
Assembly.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion ?? "unknown");
[HttpGet("/api/version")]
[HttpGet("/api/version", Name="GetVersion")]
[Tags("Version")]
[EndpointSummary("Get version")]
public string GetVersion() => Version;
public CombinedVersion GetVersion() => Version;
public record CombinedVersion(int ApiVersion, string AppVersion);
}