Files
ersatztv/ErsatzTV.Application/Playouts/Queries/GetPlayoutItemSchedulingContextHandler.cs
T
timothyandClaude Fable 5 f1b3879d51 feat(api): playout erase/scheduling-context + collection custom-order (#210, #211)
Backend slice for the ChicoryTV playouts and collections screens.

PlayoutController:
- POST /api/playouts/{id}/erase-items (204; 404 pre-check; 422 unless
  Block/Sequential/Scripted) -> ErasePlayoutItems
- POST /api/playouts/{id}/erase-items-and-history (204; 404; 422 unless
  Classic/Block/Sequential/Scripted) -> ErasePlayoutHistory
- GET /api/playouts/items/{id}/scheduling-context (200/404) decodes a
  playout item's stored context by row id via a new
  GetPlayoutItemSchedulingContext query that reuses ProcessSchedulingContext
- PlayoutItemResponseModel gains HasSchedulingContext (no raw JSON in list)
- PlayoutListItemResponseModel gains PlayoutMode (ChannelNumber already present)

CollectionController:
- PUT /api/collections/{id}/custom-order (204; 404 pre-check; 422) with
  UpdateCollectionCustomOrderRequest deriving CustomIndex from array order
- GetCollectionItemsHandler orders by CustomIndex (nulls last) then title/id
  when the collection's UseCustomPlaybackOrder is set

Tests: controller route + behavior tests, OpenAPI ProblemDetails TestCases,
GetCollectionItems custom-order handler test. Regenerated v1.json, v1.d.ts,
endpoint-index.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 22:05:51 +02:00

34 lines
1.3 KiB
C#

using ErsatzTV.Application.ProgramSchedules;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.Playouts;
public class GetPlayoutItemSchedulingContextHandler(
IDbContextFactory<TvContext> dbContextFactory,
IMediator mediator)
: IRequestHandler<GetPlayoutItemSchedulingContext, Option<string>>
{
public async Task<Option<string>> Handle(
GetPlayoutItemSchedulingContext request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
string serializedContext = await dbContext.PlayoutItems
.AsNoTracking()
.Where(pi => pi.Id == request.PlayoutItemId)
.Select(pi => pi.SchedulingContext)
.SingleOrDefaultAsync(cancellationToken);
if (string.IsNullOrWhiteSpace(serializedContext))
{
return Option<string>.None;
}
// Decode/enrich exactly the way the troubleshooting decode path does, reusing the
// single ProcessSchedulingContext handler so any future format change stays in one place.
return await mediator.Send(new ProcessSchedulingContext(serializedContext), cancellationToken);
}
}