Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 5s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m11s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m51s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Fans the frozen Block recipe (api-conventions §7a) across the five Diff/Scalar replace-all endpoints, completing the #253 PR2→PR4 arc's implementable core: - #6 Collection custom-order, #7 Playout alternate-schedules, #8 Playout templates (shared Playout.Version), #9 MultiCollection, #10 RerunCollection — each: pre-check 412 as a standalone Either after validation (H2, subtype survives the Join flatten), unconditional Version++ (M1), guarded save, controller If-Match/ETag/400/412, SPA editor ETag round-trip + 412 conflict dialog. - H1: the two Playout handlers' catch(Exception)→422 restructured so the guard's PreconditionFailedError returns before the catch (412, not 422). - M2: RerunCollection/Collection refresh runs unconditionally on save; MultiCollection keeps its name-only→no-rebuild optimization by bumping on the first (name) save. - H3: UpdateDefaultDecoHandler bulk-bumps Playout.Version via .SetProperty. - Shared ConcurrencyHeaders.MalformedIfMatchProblem() for the 400 guard. - Deferred (→ #269): same-root non-bulk sibling config writers' ETag rotation. Tests: per-handler pre-check/bump concurrency tests (Playout ×2 incl. non-vacuous racing-save backstop, Rerun, Multi incl. name-only-no-rebuild M2, Collection); controller tests get a DefaultHttpContext for the header read/write. Docs: api-conventions §7a fan-out status, spa-conventions §4a list-editor note, decisions. Refs #253 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
53 lines
2.3 KiB
C#
53 lines
2.3 KiB
C#
using System.Threading.Channels;
|
|
using ErsatzTV.Application.Playouts;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Scheduling;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ErsatzTV.Application.Scheduling;
|
|
|
|
public class UpdateDefaultDecoHandler(
|
|
IDbContextFactory<TvContext> dbContextFactory,
|
|
ChannelWriter<IBackgroundServiceRequest> channel)
|
|
: IRequestHandler<UpdateDefaultDeco, Option<BaseError>>
|
|
{
|
|
public async Task<Option<BaseError>> Handle(UpdateDefaultDeco request, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
|
|
|
int updated = await dbContext.Playouts
|
|
.Where(p => p.Id == request.PlayoutId)
|
|
.ExecuteUpdateAsync(
|
|
u => u
|
|
.SetProperty(p => p.DecoId, p => request.DecoId)
|
|
// Bump the shared Playout.Version so any open alternate-schedule/template editor tab
|
|
// (which round-trips this same token) detects the deco change and reloads (#253 §7a).
|
|
// Bulk ExecuteUpdate bypasses change-tracking, so bump via SetProperty, not Version++.
|
|
.SetProperty(p => p.Version, p => p.Version + 1),
|
|
cancellationToken);
|
|
|
|
// Changing a playout's default deco only takes effect on a Reset build (deco content is applied
|
|
// during Reset, and BlockKey has no deco dimension to self-heal) — same stale-until-Reset class
|
|
// as #251. Enqueue a Reset for the affected playout, but only if a row was actually updated: a
|
|
// request for a nonexistent playout must not queue a build for an id that isn't there (keeps the
|
|
// enqueued set equal to the affected set). CancellationToken.None so the rebuild isn't dropped
|
|
// after the assignment has already been persisted.
|
|
if (updated > 0)
|
|
{
|
|
await channel.WriteAsync(
|
|
new BuildPlayout(request.PlayoutId, PlayoutBuildMode.Reset),
|
|
CancellationToken.None);
|
|
}
|
|
|
|
return Option<BaseError>.None;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BaseError.New(ex.ToString());
|
|
}
|
|
}
|
|
}
|