fix(schedules): reload write-path response with read includes + order GET by index (#229)
Bug 1 (500 on watermark/graphics save): Replace/Add handlers projected the freshly-built entity graph, whose ProgramScheduleItemWatermark / -GraphicsElement join rows carry only foreign-key ids — the Watermark/GraphicsElement navs are null, and Mapper.ProjectToViewModel dereferences them unguarded, throwing an NRE that the controller surfaced as a 500 on PUT/POST. Both handlers now reload the persisted item(s) through the read-side include chain before projecting. Extracted that chain into ProgramScheduleItemQueryExtensions.IncludeScheduleItemDetails() so GET, Replace and Add share one source of truth. Masking: PersistItems returned a lazy LanguageExt Map, and the existing round-trip test only checked .IsRight — never enumerating it, so the deferred NRE never fired. The new ScheduleItemWriteProjectionTests force enumeration (as the controller's .ToList()/serialization does) and seed watermark/graphics via a separate context so the handler's fresh factory context has nothing pre-tracked. Bug 2 (server side): GetProgramScheduleItemsHandler now .OrderBy(i => i.Index) — it previously returned id order, which is not index order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,7 +60,15 @@ public class AddProgramScheduleItemHandler : ProgramScheduleItemCommandBase,
|
||||
await _channel.WriteAsync(new BuildPlayout(playout.Id, PlayoutBuildMode.Refresh), cancellationToken);
|
||||
}
|
||||
|
||||
return ProjectToViewModel(item);
|
||||
// reload with the full navigation graph before projecting: BuildItem creates the watermark/graphics
|
||||
// join rows with only their foreign-key ids set, so the tracked entities have null Watermark /
|
||||
// GraphicsElement navs that ProjectToViewModel dereferences (would 500 on POST — see #229).
|
||||
ProgramScheduleItem persisted = await dbContext.ProgramScheduleItems
|
||||
.Filter(psi => psi.Id == item.Id)
|
||||
.IncludeScheduleItemDetails()
|
||||
.SingleAsync(cancellationToken);
|
||||
|
||||
return ProjectToViewModel(persisted);
|
||||
}
|
||||
|
||||
private static async Task<Validation<BaseError, ProgramSchedule>> Validate(
|
||||
|
||||
Reference in New Issue
Block a user