feat(392): expose ProgramSchedule.padToNearestMinute on the REST API

This commit is contained in:
2026-07-23 08:03:31 +02:00
parent 75d5c385b2
commit 9ea2750cbf
23 changed files with 129 additions and 34 deletions
@@ -1,4 +1,4 @@
using ErsatzTV.Core;
using ErsatzTV.Core;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Application.ProgramSchedules;
@@ -9,4 +9,5 @@ public record CreateProgramSchedule(
bool TreatCollectionsAsShows,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior) : IRequest<Either<BaseError, CreateProgramScheduleResult>>;
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute) : IRequest<Either<BaseError, CreateProgramScheduleResult>>;
@@ -1,4 +1,4 @@
using ErsatzTV.Core;
using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -40,7 +40,8 @@ public class CreateProgramScheduleHandler(IDbContextFactory<TvContext> dbContext
TreatCollectionsAsShows = keepMultiPartEpisodesTogether && request.TreatCollectionsAsShows,
ShuffleScheduleItems = request.ShuffleScheduleItems,
RandomStartPoint = request.RandomStartPoint,
FixedStartTimeBehavior = request.FixedStartTimeBehavior
FixedStartTimeBehavior = request.FixedStartTimeBehavior,
PadToNearestMinute = request.PadToNearestMinute is int m && m > 0 ? m : null
};
});
@@ -1,4 +1,4 @@
using ErsatzTV.Core;
using ErsatzTV.Core;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Application.ProgramSchedules;
@@ -10,4 +10,5 @@ public record UpdateProgramSchedule(
bool TreatCollectionsAsShows,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior) : IRequest<Either<BaseError, UpdateProgramScheduleResult>>;
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute) : IRequest<Either<BaseError, UpdateProgramScheduleResult>>;
@@ -40,12 +40,15 @@ public class UpdateProgramScheduleHandler(
CancellationToken cancellationToken)
{
// we need to refresh playouts if the playback order or keep multi-episodes has been modified
int? normalizedPad = request.PadToNearestMinute is int upm && upm > 0 ? upm : null;
bool needToRefreshPlayout =
programSchedule.KeepMultiPartEpisodesTogether != request.KeepMultiPartEpisodesTogether ||
programSchedule.TreatCollectionsAsShows != request.TreatCollectionsAsShows ||
programSchedule.ShuffleScheduleItems != request.ShuffleScheduleItems ||
programSchedule.RandomStartPoint != request.RandomStartPoint ||
programSchedule.FixedStartTimeBehavior != request.FixedStartTimeBehavior;
programSchedule.FixedStartTimeBehavior != request.FixedStartTimeBehavior ||
programSchedule.PadToNearestMinute != normalizedPad;
programSchedule.Name = request.Name;
programSchedule.KeepMultiPartEpisodesTogether = request.KeepMultiPartEpisodesTogether;
@@ -54,6 +57,7 @@ public class UpdateProgramScheduleHandler(
programSchedule.ShuffleScheduleItems = request.ShuffleScheduleItems;
programSchedule.RandomStartPoint = request.RandomStartPoint;
programSchedule.FixedStartTimeBehavior = request.FixedStartTimeBehavior;
programSchedule.PadToNearestMinute = normalizedPad;
// bump the optimistic-concurrency token so this config edit rotates other clients' ETags (#253).
// Force-write past a concurrent Version bump (e.g. a parallel schedule-items replace) instead of
@@ -1,4 +1,4 @@
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Domain;
namespace ErsatzTV.Application.ProgramSchedules;
@@ -13,6 +13,7 @@ internal static class Mapper
programSchedule.ShuffleScheduleItems,
programSchedule.RandomStartPoint,
programSchedule.FixedStartTimeBehavior,
programSchedule.PadToNearestMinute,
programSchedule.Version);
internal static ProgramScheduleItemViewModel ProjectToViewModel(ProgramScheduleItem programScheduleItem) =>
@@ -1,4 +1,4 @@
using ErsatzTV.Core.Scheduling;
using ErsatzTV.Core.Scheduling;
namespace ErsatzTV.Application.ProgramSchedules;
@@ -10,4 +10,5 @@ public record ProgramScheduleViewModel(
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute,
int Version);
@@ -1,4 +1,4 @@
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.ProgramSchedules;
@@ -20,6 +20,7 @@ public class GetAllProgramSchedulesHandler(IDbContextFactory<TvContext> dbContex
ps.ShuffleScheduleItems,
ps.RandomStartPoint,
ps.FixedStartTimeBehavior,
ps.PadToNearestMinute,
ps.Version))
.ToListAsync(cancellationToken);
}
@@ -13,4 +13,5 @@ public record ProgramScheduleResponseModel(
bool TreatCollectionsAsShows,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior);
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute);
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -189,7 +189,7 @@ public class RootWriterForceVersionTests
// Name-only change → no playout refresh; the force-write must not 500 on the concurrent bump.
Either<BaseError, UpdateProgramScheduleResult> result = await handler.Handle(
new UpdateProgramSchedule(1, "After", false, false, false, false, default),
new UpdateProgramSchedule(1, "After", false, false, false, false, default, null),
CancellationToken.None);
result.IsRight.ShouldBeTrue();
@@ -30,6 +30,55 @@ public class ProgramScheduleHandlerTests
[TearDown]
public async Task TearDown() => await _db.DisposeAsync();
[Test]
public async Task Create_and_update_persist_PadToNearestMinute()
{
var createHandler = new CreateProgramScheduleHandler(_db.Factory);
Either<BaseError, CreateProgramScheduleResult> createResult = await createHandler.Handle(
new CreateProgramSchedule(
"Pad Test",
KeepMultiPartEpisodesTogether: true,
TreatCollectionsAsShows: true,
ShuffleScheduleItems: false,
RandomStartPoint: false,
FixedStartTimeBehavior.Flexible,
PadToNearestMinute: 30),
CancellationToken.None);
int scheduleId = createResult.Match(Left: _ => throw new AssertionException("Expected a Right result"), Right: r => r.ProgramScheduleId);
await using (TvContext context = _db.CreateContext())
{
ProgramSchedule? schedule = await context.ProgramSchedules.FindAsync(scheduleId);
schedule.ShouldNotBeNull();
schedule.PadToNearestMinute.ShouldBe(30);
}
var updateHandler = new UpdateProgramScheduleHandler(_db.Factory, _worker);
Either<BaseError, UpdateProgramScheduleResult> updateResult = await updateHandler.Handle(
new UpdateProgramSchedule(
scheduleId,
"Pad Test",
KeepMultiPartEpisodesTogether: true,
TreatCollectionsAsShows: true,
ShuffleScheduleItems: false,
RandomStartPoint: false,
FixedStartTimeBehavior.Flexible,
PadToNearestMinute: null),
CancellationToken.None);
updateResult.IsRight.ShouldBeTrue();
await using (TvContext context = _db.CreateContext())
{
ProgramSchedule? schedule = await context.ProgramSchedules.FindAsync(scheduleId);
schedule.ShouldNotBeNull();
schedule.PadToNearestMinute.ShouldBeNull();
}
}
[Test]
public async Task Update_Should_Return_NotFoundError_When_Schedule_Missing()
{
@@ -125,7 +174,8 @@ public class ProgramScheduleHandlerTests
TreatCollectionsAsShows: true,
ShuffleScheduleItems: false,
RandomStartPoint: false,
FixedStartTimeBehavior.Flexible);
FixedStartTimeBehavior.Flexible,
PadToNearestMinute: null);
private static AddProgramScheduleItem MakeAdd(int scheduleId, CollectionType collectionType) =>
new(
@@ -1384,7 +1384,7 @@ public class PlayoutControllerTests
new(0, programScheduleId, [], [], [], false, 1, 1, null, 12, 31, null);
private static ProgramScheduleViewModel MakeScheduleVm(int id) =>
new(id, $"Schedule {id}", false, false, false, false, FixedStartTimeBehavior.Strict, 0);
new(id, $"Schedule {id}", false, false, false, false, FixedStartTimeBehavior.Strict, null, 0);
private static TemplateViewModel MakeTemplateViewModel(int id) =>
new(id, 1, "Group", $"Template {id}", 0);
@@ -80,7 +80,7 @@ public class ScheduleControllerTests
created.StatusCode.ShouldBe(201);
created.Location.ShouldBe("/api/v1/schedules/5");
created.Value.ShouldBe(
new ProgramScheduleResponseModel(5, "Daily", true, true, false, false, FixedStartTimeBehavior.Flexible));
new ProgramScheduleResponseModel(5, "Daily", true, true, false, false, FixedStartTimeBehavior.Flexible, null));
}
[Test]
@@ -130,7 +130,7 @@ public class ScheduleControllerTests
IActionResult result = await _controller.Update(7, MakeUpdateScheduleRequest("Updated"), CancellationToken.None);
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBe(
new ProgramScheduleResponseModel(7, "Updated", true, true, false, false, FixedStartTimeBehavior.Flexible));
new ProgramScheduleResponseModel(7, "Updated", true, true, false, false, FixedStartTimeBehavior.Flexible, null));
await _mediator.Received(1).Send(
Arg.Is<UpdateProgramSchedule>(c => c.ProgramScheduleId == 7 && c.Name == "Updated"),
Arg.Any<CancellationToken>());
@@ -182,7 +182,7 @@ public class ScheduleControllerTests
IActionResult result = await _controller.GetById(4, CancellationToken.None);
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBe(
new ProgramScheduleResponseModel(4, "Daily", true, true, false, false, FixedStartTimeBehavior.Flexible));
new ProgramScheduleResponseModel(4, "Daily", true, true, false, false, FixedStartTimeBehavior.Flexible, null));
}
[Test]
@@ -393,7 +393,8 @@ public class ScheduleControllerTests
TreatCollectionsAsShows: true,
ShuffleScheduleItems: true,
RandomStartPoint: true,
FixedStartTimeBehavior: FixedStartTimeBehavior.Flexible);
FixedStartTimeBehavior: FixedStartTimeBehavior.Flexible,
PadToNearestMinute: null);
private static UpdateScheduleRequest MakeUpdateScheduleRequest(string name) =>
new(
@@ -402,7 +403,8 @@ public class ScheduleControllerTests
TreatCollectionsAsShows: true,
ShuffleScheduleItems: true,
RandomStartPoint: true,
FixedStartTimeBehavior: FixedStartTimeBehavior.Flexible);
FixedStartTimeBehavior: FixedStartTimeBehavior.Flexible,
PadToNearestMinute: null);
private static ScheduleItemRequest MakeItemRequest(PlayoutMode playoutMode) =>
new(
@@ -446,7 +448,7 @@ public class ScheduleControllerTests
SubtitleMode: null);
private static ProgramScheduleViewModel MakeSchedule(int id, string name, int version = 0) =>
new(id, name, true, true, false, false, FixedStartTimeBehavior.Flexible, version);
new(id, name, true, true, false, false, FixedStartTimeBehavior.Flexible, null, version);
private static ProgramScheduleItemOneViewModel MakeOneItem(int id) =>
new(
@@ -9,7 +9,8 @@ public record CreateScheduleRequest(
bool TreatCollectionsAsShows,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute)
{
public CreateProgramSchedule ToCreateCommand() =>
new(
@@ -18,5 +19,6 @@ public record CreateScheduleRequest(
TreatCollectionsAsShows,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior);
FixedStartTimeBehavior,
PadToNearestMinute);
}
@@ -9,7 +9,8 @@ public record UpdateScheduleRequest(
bool TreatCollectionsAsShows,
bool ShuffleScheduleItems,
bool RandomStartPoint,
FixedStartTimeBehavior FixedStartTimeBehavior)
FixedStartTimeBehavior FixedStartTimeBehavior,
int? PadToNearestMinute)
{
public UpdateProgramSchedule ToCommand(int id) =>
new(
@@ -19,5 +20,6 @@ public record UpdateScheduleRequest(
TreatCollectionsAsShows,
ShuffleScheduleItems,
RandomStartPoint,
FixedStartTimeBehavior);
FixedStartTimeBehavior,
PadToNearestMinute);
}
@@ -228,5 +228,6 @@ public class ScheduleController(IMediator mediator) : ControllerBase
vm.TreatCollectionsAsShows,
vm.ShuffleScheduleItems,
vm.RandomStartPoint,
vm.FixedStartTimeBehavior);
vm.FixedStartTimeBehavior,
vm.PadToNearestMinute);
}
+27 -3
View File
@@ -25580,7 +25580,8 @@
"treatCollectionsAsShows",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
"fixedStartTimeBehavior",
"padToNearestMinute"
],
"type": "object",
"properties": {
@@ -25604,6 +25605,13 @@
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
},
"padToNearestMinute": {
"type": [
"null",
"integer"
],
"format": "int32"
}
}
},
@@ -29198,7 +29206,8 @@
"treatCollectionsAsShows",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
"fixedStartTimeBehavior",
"padToNearestMinute"
],
"type": "object",
"properties": {
@@ -29223,6 +29232,13 @@
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
},
"padToNearestMinute": {
"type": [
"null",
"integer"
],
"format": "int32"
}
}
},
@@ -32351,7 +32367,8 @@
"treatCollectionsAsShows",
"shuffleScheduleItems",
"randomStartPoint",
"fixedStartTimeBehavior"
"fixedStartTimeBehavior",
"padToNearestMinute"
],
"type": "object",
"properties": {
@@ -32375,6 +32392,13 @@
},
"fixedStartTimeBehavior": {
"$ref": "#/components/schemas/FixedStartTimeBehavior"
},
"padToNearestMinute": {
"type": [
"null",
"integer"
],
"format": "int32"
}
}
},
+3
View File
@@ -548,6 +548,7 @@ export interface components {
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
"padToNearestMinute": null | number;
};
"CreateSmartCollectionRequest": {
"name": null | string;
@@ -1231,6 +1232,7 @@ export interface components {
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
"padToNearestMinute": null | number;
};
"RemoteConnectionResponseModel": {
"address": string;
@@ -1807,6 +1809,7 @@ export interface components {
"shuffleScheduleItems": boolean;
"randomStartPoint": boolean;
"fixedStartTimeBehavior": components["schemas"]["FixedStartTimeBehavior"];
"padToNearestMinute": null | number;
};
"UpdateSmartCollectionRequest": {
"name": null | string;