@@ -0,0 +1,22 @@
|
||||
#nullable enable
|
||||
namespace ErsatzTV.Core.Api.Channels;
|
||||
|
||||
public record AutoTuneProposalResponseModel(
|
||||
string Axis,
|
||||
string Value,
|
||||
string Name,
|
||||
string Number,
|
||||
int ItemCount,
|
||||
bool AlreadyExists);
|
||||
|
||||
public record AutoTuneChannelResultModel(
|
||||
string Name,
|
||||
string Status,
|
||||
int? ChannelId,
|
||||
string? Reason);
|
||||
|
||||
public record AutoTuneResultResponseModel(
|
||||
List<AutoTuneChannelResultModel> Results,
|
||||
int CreatedCount,
|
||||
int SkippedCount,
|
||||
int FailedCount);
|
||||
@@ -214,6 +214,47 @@ public class ChannelController(
|
||||
return result.ToDeletedResult();
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/channels/auto-tune/preview", Name = "PreviewAutoTuneChannels")]
|
||||
[Tags("Channels")]
|
||||
[EndpointSummary("Preview auto-tuned channels")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<AutoTuneProposalResponseModel>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
||||
public async Task<IActionResult> PreviewAutoTune(
|
||||
[Required][FromBody] PreviewAutoTuneChannelsRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Either<BaseError, List<AutoTuneProposal>> result =
|
||||
await mediator.Send(request.ToCommand(), cancellationToken);
|
||||
return result.Match<IActionResult>(
|
||||
Left: error => error.ToErrorResult(),
|
||||
Right: proposals => new OkObjectResult(proposals.Select(ProjectToResponseModel).ToList()));
|
||||
}
|
||||
|
||||
[HttpPost("/api/v1/channels/auto-tune", Name = "CreateAutoTunedChannels")]
|
||||
[Tags("Channels")]
|
||||
[EndpointSummary("Create auto-tuned channels")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(AutoTuneResultResponseModel), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> CreateAutoTuned(
|
||||
[Required][FromBody] CreateAutoTunedChannelsRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
AutoTuneResult result = await mediator.Send(request.ToCommand(), cancellationToken);
|
||||
return new OkObjectResult(ProjectToResponseModel(result));
|
||||
}
|
||||
|
||||
private static AutoTuneProposalResponseModel ProjectToResponseModel(AutoTuneProposal p) =>
|
||||
new(p.Axis.ToString(), p.Value, p.Name, p.Number, p.ItemCount, p.AlreadyExists);
|
||||
|
||||
private static AutoTuneResultResponseModel ProjectToResponseModel(AutoTuneResult r) =>
|
||||
new(
|
||||
r.Results.Select(o => new AutoTuneChannelResultModel(
|
||||
o.Name, o.Status.ToString(), o.ChannelId, o.Reason)).ToList(),
|
||||
r.CreatedCount,
|
||||
r.SkippedCount,
|
||||
r.FailedCount);
|
||||
|
||||
[HttpPost("/api/v1/channels/{id:int}/playout/reset")]
|
||||
[Tags("Channels")]
|
||||
[EndpointSummary("Reset channel playout")]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using ErsatzTV.Application.Channels;
|
||||
using ErsatzTV.Core.Domain;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
public record PreviewAutoTuneChannelsRequest(
|
||||
List<AutoTuneAxis> Axes,
|
||||
int MinItems,
|
||||
int StartingNumber)
|
||||
{
|
||||
public PreviewAutoTuneChannels ToCommand() => new(Axes, MinItems, StartingNumber);
|
||||
}
|
||||
|
||||
public record CreateAutoTunedChannelsRequest(
|
||||
int TemplateId,
|
||||
string Group,
|
||||
List<AutoTunedChannelRequest> Channels)
|
||||
{
|
||||
public CreateAutoTunedChannels ToCommand() =>
|
||||
new(TemplateId, Group, Channels.Select(c => c.ToCommand()).ToList());
|
||||
}
|
||||
|
||||
public record AutoTunedChannelRequest(
|
||||
AutoTuneAxis Axis,
|
||||
string Value,
|
||||
string Name,
|
||||
string Number)
|
||||
{
|
||||
public AutoTuneChannelSelection ToCommand() => new(Axis, Value, Name, Number);
|
||||
}
|
||||
Reference in New Issue
Block a user