feat(#259): id-based reconcile for schedule-items replace (backend + DTO)
Add optional `int? Id` to ScheduleItemRequest/ReplaceProgramScheduleItem so a client can round-trip each existing item's server id. When ids are present, ReplaceProgramScheduleItemsHandler reconciles by id (not array position), so an item's persisted fill-group/shuffle state (PlayoutScheduleItemFillGroupIndex, FK OnDelete Cascade) follows the logical item across reorders/inserts instead of being inherited by whatever previously occupied its new slot (#259, split from #252/#253). A fully id-less payload keeps the verbatim positional fallback. Guards (inside PersistItems, after CheckVersion so 412 precedes 422): duplicate id -> 422; id not in this schedule -> 422 (a stale id under Phase-1 force-write is a live lost-update signal, not a new item). Index stays array-position derived. Regenerated v1.json + TS client. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,14 @@ using ErsatzTV.Core.Scheduling;
|
||||
|
||||
namespace ErsatzTV.Controllers.Api.Requests;
|
||||
|
||||
/// <param name="Id">
|
||||
/// Server-assigned identity of an existing schedule item, as returned by GET /api/schedules/{id}/items.
|
||||
/// Omit (or send null / 0) for a new item. On a replace, the item carrying this id keeps its persisted
|
||||
/// fill-group/shuffle progression even when moved to a different position. Unknown or duplicated ids are
|
||||
/// rejected with 422 — never fabricate an id.
|
||||
/// </param>
|
||||
public record ScheduleItemRequest(
|
||||
int? Id,
|
||||
StartType StartType,
|
||||
TimeSpan? StartTime,
|
||||
FixedStartTimeBehavior? FixedStartTimeBehavior,
|
||||
@@ -86,6 +93,9 @@ public record ScheduleItemRequest(
|
||||
|
||||
public ReplaceProgramScheduleItem ToReplaceCommand(int index) =>
|
||||
new(
|
||||
// normalize the two-state client value (null / 0 / positive) to the handler's null-or-real
|
||||
// contract so 0-defaulting clients read as "new item" rather than "existing item 0"
|
||||
Id is > 0 ? Id : null,
|
||||
index,
|
||||
StartType,
|
||||
StartTime,
|
||||
|
||||
Reference in New Issue
Block a user