feat(api): REST endpoints for blocks, block groups, items, preview + scheduling search pickers
Adds BlockController (block groups + blocks CRUD, items GET, full replace, non-persisting preview) mirroring ScheduleController, plus four scheduling search picker endpoints on SearchController (collections, television shows, television seasons, smart collections). Response DTOs in ErsatzTV.Core/Api/ Scheduling; request DTOs with ToCommand index auto-assignment. #144 S1 (#162) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
#nullable enable
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
public record BlockGroupResponseModel(int Id, string Name);
|
||||
@@ -0,0 +1,24 @@
|
||||
#nullable enable
|
||||
using ErsatzTV.Core.Domain;
|
||||
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
public record BlockItemResponseModel(
|
||||
int Id,
|
||||
int Index,
|
||||
CollectionType CollectionType,
|
||||
int? CollectionId,
|
||||
string? CollectionName,
|
||||
int? MultiCollectionId,
|
||||
string? MultiCollectionName,
|
||||
int? SmartCollectionId,
|
||||
string? SmartCollectionName,
|
||||
int? MediaItemId,
|
||||
string? MediaItemName,
|
||||
string SearchTitle,
|
||||
string SearchQuery,
|
||||
PlaybackOrder PlaybackOrder,
|
||||
bool IncludeInProgramGuide,
|
||||
bool DisableWatermarks,
|
||||
List<int> WatermarkIds,
|
||||
List<int> GraphicsElementIds);
|
||||
@@ -0,0 +1,8 @@
|
||||
#nullable enable
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
public record BlockPreviewItemResponseModel(
|
||||
string Title,
|
||||
TimeSpan Start,
|
||||
TimeSpan Finish,
|
||||
string Duration);
|
||||
@@ -0,0 +1,12 @@
|
||||
#nullable enable
|
||||
using ErsatzTV.Core.Domain.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
public record BlockResponseModel(
|
||||
int Id,
|
||||
int GroupId,
|
||||
string GroupName,
|
||||
string Name,
|
||||
int Minutes,
|
||||
BlockStopScheduling StopScheduling);
|
||||
@@ -0,0 +1,13 @@
|
||||
#nullable enable
|
||||
using ErsatzTV.Core.Domain.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
public record BlockWithItemsResponseModel(
|
||||
int Id,
|
||||
int GroupId,
|
||||
string GroupName,
|
||||
string Name,
|
||||
int Minutes,
|
||||
BlockStopScheduling StopScheduling,
|
||||
List<BlockItemResponseModel> Items);
|
||||
@@ -0,0 +1,8 @@
|
||||
#nullable enable
|
||||
namespace ErsatzTV.Core.Api.Scheduling;
|
||||
|
||||
/// <summary>
|
||||
/// A lightweight {id, name} option used by the block/schedule editor pickers
|
||||
/// (collection, television show, television season, smart collection search).
|
||||
/// </summary>
|
||||
public record SchedulingPickerOptionResponseModel(int Id, string Name);
|
||||
@@ -25,6 +25,7 @@ public class ApiControllerSecurityTests
|
||||
{
|
||||
Type[] apiControllers =
|
||||
[
|
||||
typeof(BlockController),
|
||||
typeof(ChannelController),
|
||||
typeof(CollectionController),
|
||||
typeof(FFmpegProfileController),
|
||||
|
||||
@@ -68,6 +68,17 @@ public class ApiErrorResponseMetadataTests
|
||||
[TestCase(typeof(ScheduleController), nameof(ScheduleController.ReplaceItems), StatusCodes.Status422UnprocessableEntity)]
|
||||
[TestCase(typeof(ScheduleController), nameof(ScheduleController.DeleteItem), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(ScheduleController), nameof(ScheduleController.DeleteItem), StatusCodes.Status422UnprocessableEntity)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.GetById), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.CreateGroup), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.CreateGroup), StatusCodes.Status422UnprocessableEntity)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.DeleteGroup), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Create), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Create), StatusCodes.Status422UnprocessableEntity)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Delete), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.GetItems), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Replace), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Replace), StatusCodes.Status422UnprocessableEntity)]
|
||||
[TestCase(typeof(BlockController), nameof(BlockController.Preview), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(PlayoutController), nameof(PlayoutController.GetById), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(PlayoutController), nameof(PlayoutController.Create), StatusCodes.Status404NotFound)]
|
||||
[TestCase(typeof(PlayoutController), nameof(PlayoutController.Create), StatusCodes.Status422UnprocessableEntity)]
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
using System.Reflection;
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
using ErsatzTV.Controllers.Api;
|
||||
using ErsatzTV.Controllers.Api.Requests;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Api.Scheduling;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.Domain.Scheduling;
|
||||
using LanguageExt;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Shouldly;
|
||||
using static LanguageExt.Prelude;
|
||||
using Unit = LanguageExt.Unit;
|
||||
|
||||
namespace ErsatzTV.Tests.Controllers;
|
||||
|
||||
[TestFixture]
|
||||
public class BlockControllerTests
|
||||
{
|
||||
private BlockController _controller = null!;
|
||||
private IMediator _mediator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mediator = Substitute.For<IMediator>();
|
||||
_controller = new BlockController(_mediator);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Controller_Should_Expose_Idiomatic_Rest_Routes()
|
||||
{
|
||||
ShouldHaveActionRoute(nameof(BlockController.GetGroups), "GET", "/api/blocks/groups");
|
||||
ShouldHaveActionRoute(nameof(BlockController.CreateGroup), "POST", "/api/blocks/groups");
|
||||
ShouldHaveActionRoute(nameof(BlockController.DeleteGroup), "DELETE", "/api/blocks/groups/{id:int}");
|
||||
ShouldHaveActionRoute(nameof(BlockController.GetAll), "GET", "/api/blocks");
|
||||
ShouldHaveActionRoute(nameof(BlockController.GetById), "GET", "/api/blocks/{id:int}");
|
||||
ShouldHaveActionRoute(nameof(BlockController.Create), "POST", "/api/blocks");
|
||||
ShouldHaveActionRoute(nameof(BlockController.Delete), "DELETE", "/api/blocks/{id:int}");
|
||||
ShouldHaveActionRoute(nameof(BlockController.GetItems), "GET", "/api/blocks/{id:int}/items");
|
||||
ShouldHaveActionRoute(nameof(BlockController.Replace), "PUT", "/api/blocks/{id:int}");
|
||||
ShouldHaveActionRoute(nameof(BlockController.Preview), "POST", "/api/blocks/{id:int}/preview");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateGroup_Should_Return_201_With_Location_And_Body()
|
||||
{
|
||||
_mediator.Send(Arg.Any<CreateBlockGroup>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Right<BaseError, BlockGroupViewModel>(new BlockGroupViewModel(5, "Prime Time")));
|
||||
|
||||
IActionResult result = await _controller.CreateGroup(
|
||||
new CreateBlockGroupRequest("Prime Time"),
|
||||
CancellationToken.None);
|
||||
|
||||
var created = result.ShouldBeOfType<CreatedResult>();
|
||||
created.Location.ShouldBe("/api/blocks/groups/5");
|
||||
created.Value.ShouldBeOfType<BlockGroupResponseModel>().Name.ShouldBe("Prime Time");
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<CreateBlockGroup>(c => c.Name == "Prime Time"),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateGroup_Should_Return_422_On_Validation_Error()
|
||||
{
|
||||
_mediator.Send(Arg.Any<CreateBlockGroup>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Left<BaseError, BlockGroupViewModel>(BaseError.New("bad")));
|
||||
|
||||
IActionResult result = await _controller.CreateGroup(
|
||||
new CreateBlockGroupRequest(string.Empty),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<UnprocessableEntityObjectResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteGroup_Should_Return_204_When_Exists()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetAllBlockGroups>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<BlockGroupViewModel> { new(3, "Prime Time") });
|
||||
_mediator.Send(Arg.Any<DeleteBlockGroup>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BaseError>.None);
|
||||
|
||||
IActionResult result = await _controller.DeleteGroup(3, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NoContentResult>();
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<DeleteBlockGroup>(c => c.BlockGroupId == 3),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteGroup_Should_Return_404_When_Missing()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetAllBlockGroups>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<BlockGroupViewModel>());
|
||||
|
||||
IActionResult result = await _controller.DeleteGroup(99, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
await _mediator.DidNotReceive().Send(Arg.Any<DeleteBlockGroup>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAll_Should_Map_ViewModels_To_Response_Models()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetAllBlocks>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<BlockViewModel> { MakeBlock(1, 2, "Morning") });
|
||||
|
||||
List<BlockResponseModel> result = await _controller.GetAll(CancellationToken.None);
|
||||
|
||||
result.Count.ShouldBe(1);
|
||||
result[0].Id.ShouldBe(1);
|
||||
result[0].GroupId.ShouldBe(2);
|
||||
result[0].Name.ShouldBe("Morning");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Create_Should_Return_201_And_Map_Request()
|
||||
{
|
||||
_mediator.Send(Arg.Any<CreateBlock>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Right<BaseError, BlockViewModel>(MakeBlock(8, 2, "Morning")));
|
||||
|
||||
IActionResult result = await _controller.Create(
|
||||
new CreateBlockRequest(2, "Morning"),
|
||||
CancellationToken.None);
|
||||
|
||||
var created = result.ShouldBeOfType<CreatedResult>();
|
||||
created.Location.ShouldBe("/api/blocks/8");
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<CreateBlock>(c => c.BlockGroupId == 2 && c.Name == "Morning"),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Create_Should_Return_422_On_Validation_Error()
|
||||
{
|
||||
_mediator.Send(Arg.Any<CreateBlock>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Left<BaseError, BlockViewModel>(BaseError.New("dupe")));
|
||||
|
||||
IActionResult result = await _controller.Create(
|
||||
new CreateBlockRequest(2, "Morning"),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<UnprocessableEntityObjectResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_Should_Return_200_For_Some()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 2, "Morning")));
|
||||
|
||||
IActionResult result = await _controller.GetById(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBeOfType<BlockResponseModel>().Id.ShouldBe(4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_Should_Return_404_For_None()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.None);
|
||||
|
||||
IActionResult result = await _controller.GetById(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_Should_Return_204_When_Exists()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 2, "Morning")));
|
||||
_mediator.Send(Arg.Any<DeleteBlock>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BaseError>.None);
|
||||
|
||||
IActionResult result = await _controller.Delete(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Delete_Should_Return_404_When_Missing()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.None);
|
||||
|
||||
IActionResult result = await _controller.Delete(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
await _mediator.DidNotReceive().Send(Arg.Any<DeleteBlock>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetItems_Should_Return_200_Ordered_By_Index()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 2, "Morning")));
|
||||
_mediator.Send(Arg.Any<GetBlockItems>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<BlockItemViewModel> { MakeItem(20, 1), MakeItem(10, 0) });
|
||||
|
||||
IActionResult result = await _controller.GetItems(4, CancellationToken.None);
|
||||
|
||||
var items = result.ShouldBeOfType<OkObjectResult>().Value.ShouldBeOfType<List<BlockItemResponseModel>>();
|
||||
items.Count.ShouldBe(2);
|
||||
items[0].Index.ShouldBe(0);
|
||||
items[1].Index.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetItems_Should_Return_404_When_Block_Missing()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.None);
|
||||
|
||||
IActionResult result = await _controller.GetItems(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Replace_Should_Return_200_With_Refreshed_Block_And_Assign_Index_And_GroupId()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 7, "Morning")));
|
||||
_mediator.Send(Arg.Any<ReplaceBlockItems>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Right<BaseError, Unit>(Unit.Default));
|
||||
_mediator.Send(Arg.Any<GetBlockItems>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<BlockItemViewModel> { MakeItem(10, 0), MakeItem(11, 1) });
|
||||
|
||||
IActionResult result = await _controller.Replace(
|
||||
4,
|
||||
new ReplaceBlockRequest(
|
||||
"Morning",
|
||||
60,
|
||||
BlockStopScheduling.BeforeDurationEnd,
|
||||
[MakeItemRequest(), MakeItemRequest()]),
|
||||
CancellationToken.None);
|
||||
|
||||
var body = result.ShouldBeOfType<OkObjectResult>().Value.ShouldBeOfType<BlockWithItemsResponseModel>();
|
||||
body.Id.ShouldBe(4);
|
||||
body.Items.Count.ShouldBe(2);
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<ReplaceBlockItems>(c =>
|
||||
c.BlockId == 4 &&
|
||||
c.BlockGroupId == 7 &&
|
||||
c.Minutes == 60 &&
|
||||
c.StopScheduling == BlockStopScheduling.BeforeDurationEnd &&
|
||||
c.Items.Count == 2 &&
|
||||
c.Items[0].Index == 0 &&
|
||||
c.Items[1].Index == 1),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Replace_Should_Return_404_When_Block_Missing()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.None);
|
||||
|
||||
IActionResult result = await _controller.Replace(
|
||||
4,
|
||||
new ReplaceBlockRequest("Morning", 60, BlockStopScheduling.AfterDurationEnd, []),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
await _mediator.DidNotReceive().Send(Arg.Any<ReplaceBlockItems>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Replace_Should_Return_422_On_Validation_Error()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 7, "Morning")));
|
||||
_mediator.Send(Arg.Any<ReplaceBlockItems>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Left<BaseError, Unit>(BaseError.New("bad minutes")));
|
||||
|
||||
IActionResult result = await _controller.Replace(
|
||||
4,
|
||||
new ReplaceBlockRequest("Morning", 7, BlockStopScheduling.AfterDurationEnd, []),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<UnprocessableEntityObjectResult>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Preview_Should_Return_200_With_Preview_Items()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.Some(MakeBlock(4, 7, "Morning")));
|
||||
_mediator.Send(Arg.Any<PreviewBlockPlayout>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PlayoutItemPreviewViewModel>
|
||||
{
|
||||
new("Show", TimeSpan.Zero, TimeSpan.FromMinutes(30), "00:30:00")
|
||||
});
|
||||
|
||||
IActionResult result = await _controller.Preview(
|
||||
4,
|
||||
new ReplaceBlockRequest("Morning", 60, BlockStopScheduling.AfterDurationEnd, [MakeItemRequest()]),
|
||||
CancellationToken.None);
|
||||
|
||||
var items = result.ShouldBeOfType<OkObjectResult>().Value
|
||||
.ShouldBeOfType<List<BlockPreviewItemResponseModel>>();
|
||||
items.Count.ShouldBe(1);
|
||||
items[0].Title.ShouldBe("Show");
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<PreviewBlockPlayout>(p => p.Data.BlockId == 4 && p.Data.BlockGroupId == 7),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Preview_Should_Return_404_When_Block_Missing()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetBlockById>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Option<BlockViewModel>.None);
|
||||
|
||||
IActionResult result = await _controller.Preview(
|
||||
4,
|
||||
new ReplaceBlockRequest("Morning", 60, BlockStopScheduling.AfterDurationEnd, []),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<NotFoundObjectResult>();
|
||||
await _mediator.DidNotReceive().Send(Arg.Any<PreviewBlockPlayout>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
private static BlockViewModel MakeBlock(int id, int groupId, string name) =>
|
||||
new(id, groupId, "Group", name, 30, BlockStopScheduling.AfterDurationEnd);
|
||||
|
||||
private static BlockItemViewModel MakeItem(int id, int index) =>
|
||||
new(
|
||||
id,
|
||||
index,
|
||||
CollectionType.SearchQuery,
|
||||
null!,
|
||||
null!,
|
||||
null!,
|
||||
null!,
|
||||
"News",
|
||||
"news",
|
||||
PlaybackOrder.Shuffle,
|
||||
IncludeInProgramGuide: true,
|
||||
DisableWatermarks: false,
|
||||
[],
|
||||
[]);
|
||||
|
||||
private static BlockItemRequest MakeItemRequest() =>
|
||||
new(
|
||||
CollectionType.SearchQuery,
|
||||
CollectionId: null,
|
||||
MultiCollectionId: null,
|
||||
SmartCollectionId: null,
|
||||
MediaItemId: null,
|
||||
SearchTitle: "News",
|
||||
SearchQuery: "news",
|
||||
PlaybackOrder: PlaybackOrder.Shuffle,
|
||||
IncludeInProgramGuide: true,
|
||||
DisableWatermarks: false,
|
||||
WatermarkIds: [],
|
||||
GraphicsElementIds: []);
|
||||
|
||||
private static void ShouldHaveActionRoute(string actionName, string httpMethod, string route)
|
||||
{
|
||||
MethodInfo action = typeof(BlockController).GetMethod(actionName)
|
||||
?? throw new AssertionException($"Missing action {actionName}");
|
||||
|
||||
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
|
||||
attribute.HttpMethods.ShouldContain(httpMethod);
|
||||
attribute.Template.ShouldBe(route);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using System.Reflection;
|
||||
using ErsatzTV.Application.MediaCollections;
|
||||
using ErsatzTV.Application.MediaItems;
|
||||
using ErsatzTV.Application.Search;
|
||||
using ErsatzTV.Controllers.Api;
|
||||
using ErsatzTV.Core.Api.Scheduling;
|
||||
using ErsatzTV.Core.Api.Search;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
@@ -71,6 +75,53 @@ public class SearchControllerTests
|
||||
ok.Value.ShouldBe(results);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SearchCollections_Should_Map_To_Picker_Options()
|
||||
{
|
||||
_mediator.Send(Arg.Any<SearchCollections>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<MediaCollectionViewModel>
|
||||
{
|
||||
new(CollectionType.Collection, 3, "Movies", false, new MediaItemState())
|
||||
});
|
||||
|
||||
List<SchedulingPickerOptionResponseModel> result =
|
||||
await _controller.SearchCollections("mov", CancellationToken.None);
|
||||
|
||||
result.ShouldHaveSingleItem();
|
||||
result[0].Id.ShouldBe(3);
|
||||
result[0].Name.ShouldBe("Movies");
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<SearchCollections>(q => q.Query == "mov"),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SearchTelevisionShows_Should_Map_MediaItemId_To_Option_Id()
|
||||
{
|
||||
_mediator.Send(Arg.Any<SearchTelevisionShows>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<NamedMediaItemViewModel> { new(42, "The Show") });
|
||||
|
||||
List<SchedulingPickerOptionResponseModel> result =
|
||||
await _controller.SearchTelevisionShows("show", CancellationToken.None);
|
||||
|
||||
result.ShouldHaveSingleItem();
|
||||
result[0].Id.ShouldBe(42);
|
||||
result[0].Name.ShouldBe("The Show");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SearchSmartCollections_Should_Map_To_Picker_Options()
|
||||
{
|
||||
_mediator.Send(Arg.Any<SearchSmartCollections>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<SmartCollectionViewModel> { new(9, "Recent", "query") });
|
||||
|
||||
List<SchedulingPickerOptionResponseModel> result =
|
||||
await _controller.SearchSmartCollections("rec", CancellationToken.None);
|
||||
|
||||
result.ShouldHaveSingleItem();
|
||||
result[0].Id.ShouldBe(9);
|
||||
}
|
||||
|
||||
private static SearchResultsResponseModel EmptyResults()
|
||||
{
|
||||
var empty = new SearchResultGroupResponseModel(0, []);
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
using ErsatzTV.Controllers.Api.Requests;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Api.Scheduling;
|
||||
using ErsatzTV.Extensions;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api;
|
||||
|
||||
[ApiController]
|
||||
public class BlockController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
[HttpGet("/api/blocks/groups", Name = "GetBlockGroups")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Get all block groups")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<BlockGroupResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<BlockGroupResponseModel>> GetGroups(CancellationToken cancellationToken)
|
||||
{
|
||||
List<BlockGroupViewModel> groups = await mediator.Send(new GetAllBlockGroups(), cancellationToken);
|
||||
return groups.Map(ProjectToResponseModel).ToList();
|
||||
}
|
||||
|
||||
[HttpPost("/api/blocks/groups")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Create a block group")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(BlockGroupResponseModel), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
||||
public async Task<IActionResult> CreateGroup(
|
||||
[Required] [FromBody] CreateBlockGroupRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Either<BaseError, BlockGroupViewModel> result =
|
||||
await mediator.Send(request.ToCommand(), cancellationToken);
|
||||
return result.ToCreatedResult(
|
||||
vm => $"/api/blocks/groups/{vm.Id}",
|
||||
vm => ProjectToResponseModel(vm));
|
||||
}
|
||||
|
||||
[HttpDelete("/api/blocks/groups/{id:int}")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Delete a block group")]
|
||||
[EndpointDescription(
|
||||
"Deletes the block group. The database cascade removes every block (and its items) in the group.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DeleteGroup(int id, CancellationToken cancellationToken)
|
||||
{
|
||||
List<BlockGroupViewModel> groups = await mediator.Send(new GetAllBlockGroups(), cancellationToken);
|
||||
if (groups.All(g => g.Id != id))
|
||||
{
|
||||
return ApiResults.NotFoundProblem();
|
||||
}
|
||||
|
||||
Option<BaseError> result = await mediator.Send(new DeleteBlockGroup(id), cancellationToken);
|
||||
return result.Match<IActionResult>(
|
||||
Some: error => error.ToErrorResult(),
|
||||
None: () => new NoContentResult());
|
||||
}
|
||||
|
||||
[HttpGet("/api/blocks")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Get all blocks")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<BlockResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<BlockResponseModel>> GetAll(CancellationToken cancellationToken)
|
||||
{
|
||||
List<BlockViewModel> blocks = await mediator.Send(new GetAllBlocks(), cancellationToken);
|
||||
return blocks.Map(ProjectToResponseModel).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("/api/blocks/{id:int}", Name = "GetBlockById")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Get a block by id")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(BlockResponseModel), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetById(int id, CancellationToken cancellationToken)
|
||||
{
|
||||
Option<BlockViewModel> result = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
return result.Map(ProjectToResponseModel).ToGetResult();
|
||||
}
|
||||
|
||||
[HttpPost("/api/blocks")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Create a block")]
|
||||
[EndpointDescription("Creates an empty block in the given block group. The block defaults to 30 minutes.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(BlockResponseModel), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
||||
public async Task<IActionResult> Create(
|
||||
[Required] [FromBody] CreateBlockRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Either<BaseError, BlockViewModel> result = await mediator.Send(request.ToCommand(), cancellationToken);
|
||||
return result.ToCreatedResult(
|
||||
vm => $"/api/blocks/{vm.Id}",
|
||||
vm => ProjectToResponseModel(vm));
|
||||
}
|
||||
|
||||
[HttpDelete("/api/blocks/{id:int}")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Delete a block")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Delete(int id, CancellationToken cancellationToken)
|
||||
{
|
||||
Option<BlockViewModel> existing = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
if (existing.IsNone)
|
||||
{
|
||||
return ApiResults.NotFoundProblem();
|
||||
}
|
||||
|
||||
Option<BaseError> result = await mediator.Send(new DeleteBlock(id), cancellationToken);
|
||||
return result.Match<IActionResult>(
|
||||
Some: error => error.ToErrorResult(),
|
||||
None: () => new NoContentResult());
|
||||
}
|
||||
|
||||
[HttpGet("/api/blocks/{id:int}/items")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Get block items")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<BlockItemResponseModel>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetItems(int id, CancellationToken cancellationToken)
|
||||
{
|
||||
Option<BlockViewModel> block = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
if (block.IsNone)
|
||||
{
|
||||
return ApiResults.NotFoundProblem();
|
||||
}
|
||||
|
||||
List<BlockItemViewModel> items = await mediator.Send(new GetBlockItems(id), cancellationToken);
|
||||
return new OkObjectResult(items.OrderBy(i => i.Index).Map(ProjectToResponseModel).ToList());
|
||||
}
|
||||
|
||||
[HttpPut("/api/blocks/{id:int}")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Replace a block and its items")]
|
||||
[EndpointDescription(
|
||||
"Replaces the block's name/minutes/stop-scheduling and its full item list. Item indexes are assigned " +
|
||||
"from the array order. Minutes must be greater than zero, divisible by 5, and at most 24 hours.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(BlockWithItemsResponseModel), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)]
|
||||
public async Task<IActionResult> Replace(
|
||||
int id,
|
||||
[Required] [FromBody] ReplaceBlockRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Option<BlockViewModel> maybeBlock = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
if (maybeBlock.IsNone)
|
||||
{
|
||||
return ApiResults.NotFoundProblem();
|
||||
}
|
||||
|
||||
int groupId = maybeBlock.Map(b => b.GroupId).IfNone(0);
|
||||
|
||||
Either<BaseError, Unit> result =
|
||||
await mediator.Send(request.ToCommand(groupId, id), cancellationToken);
|
||||
|
||||
return await result.Match(
|
||||
Left: error => Task.FromResult(error.ToErrorResult()),
|
||||
Right: async _ =>
|
||||
{
|
||||
Option<BlockViewModel> refreshed = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
List<BlockItemViewModel> items = await mediator.Send(new GetBlockItems(id), cancellationToken);
|
||||
return refreshed.Match(
|
||||
Some: vm => (IActionResult)new OkObjectResult(
|
||||
ProjectToWithItemsResponseModel(vm, items)),
|
||||
None: () => ApiResults.NotFoundProblem());
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("/api/blocks/{id:int}/preview")]
|
||||
[Tags("Blocks")]
|
||||
[EndpointSummary("Preview a block playout")]
|
||||
[EndpointDescription(
|
||||
"Builds a preview playout from the supplied block definition without persisting any changes to the " +
|
||||
"block, its items, or any playout. Returns the resulting start/finish/title/duration list.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<BlockPreviewItemResponseModel>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Preview(
|
||||
int id,
|
||||
[Required] [FromBody] ReplaceBlockRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Option<BlockViewModel> maybeBlock = await mediator.Send(new GetBlockById(id), cancellationToken);
|
||||
if (maybeBlock.IsNone)
|
||||
{
|
||||
return ApiResults.NotFoundProblem();
|
||||
}
|
||||
|
||||
int groupId = maybeBlock.Map(b => b.GroupId).IfNone(0);
|
||||
|
||||
List<PlayoutItemPreviewViewModel> preview = await mediator.Send(
|
||||
new PreviewBlockPlayout(request.ToCommand(groupId, id)),
|
||||
cancellationToken);
|
||||
|
||||
return new OkObjectResult(preview.Map(ProjectToResponseModel).ToList());
|
||||
}
|
||||
|
||||
private static BlockGroupResponseModel ProjectToResponseModel(BlockGroupViewModel vm) =>
|
||||
new(vm.Id, vm.Name);
|
||||
|
||||
private static BlockResponseModel ProjectToResponseModel(BlockViewModel vm) =>
|
||||
new(vm.Id, vm.GroupId, vm.GroupName, vm.Name, vm.Minutes, vm.StopScheduling);
|
||||
|
||||
private static BlockWithItemsResponseModel ProjectToWithItemsResponseModel(
|
||||
BlockViewModel vm,
|
||||
List<BlockItemViewModel> items) =>
|
||||
new(
|
||||
vm.Id,
|
||||
vm.GroupId,
|
||||
vm.GroupName,
|
||||
vm.Name,
|
||||
vm.Minutes,
|
||||
vm.StopScheduling,
|
||||
items.OrderBy(i => i.Index).Map(ProjectToResponseModel).ToList());
|
||||
|
||||
private static BlockItemResponseModel ProjectToResponseModel(BlockItemViewModel vm) =>
|
||||
new(
|
||||
vm.Id,
|
||||
vm.Index,
|
||||
vm.CollectionType,
|
||||
vm.Collection?.Id,
|
||||
vm.Collection?.Name,
|
||||
vm.MultiCollection?.Id,
|
||||
vm.MultiCollection?.Name,
|
||||
vm.SmartCollection?.Id,
|
||||
vm.SmartCollection?.Name,
|
||||
vm.MediaItem?.MediaItemId,
|
||||
vm.MediaItem?.Name,
|
||||
vm.SearchTitle,
|
||||
vm.SearchQuery,
|
||||
vm.PlaybackOrder,
|
||||
vm.IncludeInProgramGuide,
|
||||
vm.DisableWatermarks,
|
||||
vm.Watermarks.Map(w => w.Id).ToList(),
|
||||
vm.GraphicsElements.Map(g => g.Id).ToList());
|
||||
|
||||
private static BlockPreviewItemResponseModel ProjectToResponseModel(PlayoutItemPreviewViewModel vm) =>
|
||||
new(vm.Title, vm.Start, vm.Finish, vm.Duration);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
using ErsatzTV.Core.Domain;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
public record BlockItemRequest(
|
||||
CollectionType CollectionType,
|
||||
int? CollectionId,
|
||||
int? MultiCollectionId,
|
||||
int? SmartCollectionId,
|
||||
int? MediaItemId,
|
||||
string SearchTitle,
|
||||
string SearchQuery,
|
||||
PlaybackOrder PlaybackOrder,
|
||||
bool IncludeInProgramGuide,
|
||||
bool DisableWatermarks,
|
||||
List<int> WatermarkIds,
|
||||
List<int> GraphicsElementIds)
|
||||
{
|
||||
public ReplaceBlockItem ToReplaceItem(int index) =>
|
||||
new(
|
||||
index,
|
||||
CollectionType,
|
||||
CollectionId,
|
||||
MultiCollectionId,
|
||||
SmartCollectionId,
|
||||
MediaItemId,
|
||||
SearchTitle,
|
||||
SearchQuery,
|
||||
PlaybackOrder,
|
||||
IncludeInProgramGuide,
|
||||
DisableWatermarks,
|
||||
WatermarkIds ?? [],
|
||||
GraphicsElementIds ?? []);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
public record CreateBlockGroupRequest(string Name)
|
||||
{
|
||||
public CreateBlockGroup ToCommand() => new(Name);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
public record CreateBlockRequest(int BlockGroupId, string Name)
|
||||
{
|
||||
public CreateBlock ToCommand() => new(BlockGroupId, Name);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using ErsatzTV.Application.Scheduling;
|
||||
using ErsatzTV.Core.Domain.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
public record ReplaceBlockRequest(
|
||||
string Name,
|
||||
int Minutes,
|
||||
BlockStopScheduling StopScheduling,
|
||||
List<BlockItemRequest> Items)
|
||||
{
|
||||
public ReplaceBlockItems ToCommand(int blockGroupId, int blockId) =>
|
||||
new(
|
||||
blockGroupId,
|
||||
blockId,
|
||||
Name,
|
||||
Minutes,
|
||||
StopScheduling,
|
||||
(Items ?? []).Select((item, index) => item.ToReplaceItem(index)).ToList());
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using ErsatzTV.Application.MediaCollections;
|
||||
using ErsatzTV.Application.MediaItems;
|
||||
using ErsatzTV.Application.Search;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Api.Scheduling;
|
||||
using ErsatzTV.Core.Api.Search;
|
||||
using ErsatzTV.Extensions;
|
||||
using MediatR;
|
||||
@@ -35,4 +38,68 @@ public class SearchController(IMediator mediator) : ControllerBase
|
||||
cancellationToken);
|
||||
return new OkObjectResult(result);
|
||||
}
|
||||
|
||||
[HttpGet("/api/search/collections", Name = "SearchCollections")]
|
||||
[Tags("Search")]
|
||||
[EndpointSummary("Search collections by name")]
|
||||
[EndpointDescription("Returns matching collections as {id, name} options for scheduling editors.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<SchedulingPickerOptionResponseModel>> SearchCollections(
|
||||
[FromQuery] string query = "",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<MediaCollectionViewModel> results = await mediator.Send(
|
||||
new SearchCollections(query ?? string.Empty),
|
||||
cancellationToken);
|
||||
return results.Map(c => new SchedulingPickerOptionResponseModel(c.Id, c.Name)).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("/api/search/television-shows", Name = "SearchTelevisionShows")]
|
||||
[Tags("Search")]
|
||||
[EndpointSummary("Search television shows by name")]
|
||||
[EndpointDescription("Returns matching television shows as {id, name} options for scheduling editors.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<SchedulingPickerOptionResponseModel>> SearchTelevisionShows(
|
||||
[FromQuery] string query = "",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<NamedMediaItemViewModel> results = await mediator.Send(
|
||||
new SearchTelevisionShows(query ?? string.Empty),
|
||||
cancellationToken);
|
||||
return results.Map(s => new SchedulingPickerOptionResponseModel(s.MediaItemId, s.Name)).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("/api/search/television-seasons", Name = "SearchTelevisionSeasons")]
|
||||
[Tags("Search")]
|
||||
[EndpointSummary("Search television seasons by name")]
|
||||
[EndpointDescription("Returns matching television seasons as {id, name} options for scheduling editors.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<SchedulingPickerOptionResponseModel>> SearchTelevisionSeasons(
|
||||
[FromQuery] string query = "",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<NamedMediaItemViewModel> results = await mediator.Send(
|
||||
new SearchTelevisionSeasons(query ?? string.Empty),
|
||||
cancellationToken);
|
||||
return results.Map(s => new SchedulingPickerOptionResponseModel(s.MediaItemId, s.Name)).ToList();
|
||||
}
|
||||
|
||||
[HttpGet("/api/search/smart-collections", Name = "SearchSmartCollections")]
|
||||
[Tags("Search")]
|
||||
[EndpointSummary("Search smart collections by name")]
|
||||
[EndpointDescription("Returns matching smart collections as {id, name} options for scheduling editors.")]
|
||||
[EndpointGroupName("general")]
|
||||
[ProducesResponseType(typeof(List<SchedulingPickerOptionResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<List<SchedulingPickerOptionResponseModel>> SearchSmartCollections(
|
||||
[FromQuery] string query = "",
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
List<SmartCollectionViewModel> results = await mediator.Send(
|
||||
new SearchSmartCollections(query ?? string.Empty),
|
||||
cancellationToken);
|
||||
return results.Map(c => new SchedulingPickerOptionResponseModel(c.Id, c.Name)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user