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);
}
+1 -1
View File
@@ -953,7 +953,7 @@
collectionResult.Item1.Name,
_query);
Either<BaseError, Unit> updateResult = await Mediator.Send(request, CancellationToken);
Either<BaseError, UpdateSmartCollectionResult> updateResult = await Mediator.Send(request, CancellationToken);
updateResult.Match(
Left: error =>
{
+1 -1
View File
@@ -70,7 +70,7 @@
await _form.Validate();
if (_success)
{
Either<BaseError, Unit> result = await Mediator.Send(new UpdateSmartCollection(Id, _model.Name, _model.Query), _cts.Token);
Either<BaseError, UpdateSmartCollectionResult> result = await Mediator.Send(new UpdateSmartCollection(Id, _model.Name, _model.Query), _cts.Token);
result.Match(
_ => NavigationManager.NavigateTo("media/smart-collections"),
error =>
+305 -6
View File
@@ -5,6 +5,44 @@
"version": "1.0.0"
},
"paths": {
"/api/channels": {
"get": {
"tags": [
"Channel"
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelResponseModel"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelResponseModel"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ChannelResponseModel"
}
}
}
}
}
}
}
},
"/api/channels/{channelNumber}/playout/reset": {
"post": {
"tags": [
@@ -199,29 +237,169 @@
}
}
},
"/api/version": {
"/api/collections/smart": {
"get": {
"tags": [
"Version"
"SmartCollection"
],
"summary": "Get version",
"operationId": "GetSmartCollections",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
"type": "array",
"items": {
"$ref": "#/components/schemas/SmartCollectionResponseModel"
}
}
},
"application/json": {
"schema": {
"type": "string"
"type": "array",
"items": {
"$ref": "#/components/schemas/SmartCollectionResponseModel"
}
}
},
"text/json": {
"schema": {
"type": "string"
"type": "array",
"items": {
"$ref": "#/components/schemas/SmartCollectionResponseModel"
}
}
}
}
}
}
}
},
"/api/collections/smart/new": {
"post": {
"tags": [
"SmartCollection"
],
"operationId": "CreateSmartCollection",
"requestBody": {
"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/CreateSmartCollection"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateSmartCollection"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CreateSmartCollection"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/CreateSmartCollection"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/collections/smart/update": {
"put": {
"tags": [
"SmartCollection"
],
"operationId": "UpdateSmartCollection",
"requestBody": {
"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/UpdateSmartCollection"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateSmartCollection"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/UpdateSmartCollection"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/UpdateSmartCollection"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/collections/smart/delete/{id}": {
"delete": {
"tags": [
"SmartCollection"
],
"operationId": "DeleteSmartCollection",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/version": {
"get": {
"tags": [
"Version"
],
"summary": "Get version",
"operationId": "GetVersion",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/CombinedVersion"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CombinedVersion"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CombinedVersion"
}
}
}
@@ -232,6 +410,77 @@
},
"components": {
"schemas": {
"ChannelResponseModel": {
"required": [
"id",
"number",
"name",
"fFmpegProfile",
"language",
"streamingMode"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"number": {
"type": "string",
"nullable": true
},
"name": {
"type": "string",
"nullable": true
},
"fFmpegProfile": {
"type": "string",
"nullable": true
},
"language": {
"type": "string",
"nullable": true
},
"streamingMode": {
"type": "string",
"nullable": true
}
}
},
"CombinedVersion": {
"required": [
"apiVersion",
"appVersion"
],
"type": "object",
"properties": {
"apiVersion": {
"type": "integer",
"format": "int32"
},
"appVersion": {
"type": "string",
"nullable": true
}
}
},
"CreateSmartCollection": {
"required": [
"query",
"name"
],
"type": "object",
"properties": {
"query": {
"type": "string",
"nullable": true
},
"name": {
"type": "string",
"nullable": true
}
}
},
"HlsSessionModel": {
"required": [
"channelNumber",
@@ -274,10 +523,57 @@
"default": false
}
}
},
"SmartCollectionResponseModel": {
"required": [
"id",
"name",
"query"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"nullable": true
},
"query": {
"type": "string",
"nullable": true
}
}
},
"UpdateSmartCollection": {
"required": [
"id",
"name",
"query"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"nullable": true
},
"query": {
"type": "string",
"nullable": true
}
}
}
}
},
"tags": [
{
"name": "Channel"
},
{
"name": "Channels"
},
@@ -290,6 +586,9 @@
{
"name": "Sessions"
},
{
"name": "SmartCollection"
},
{
"name": "Version"
}