Add InterstitialGroups service and enhance SlotWriter and related components for interstitial handling
ci / build-backend (push) Successful in 1m18s
ci / build-frontend (push) Successful in 43s
ci / tests (push) Successful in 3m38s
ci / sonar (push) Successful in 3m38s

Introduced the InterstitialGroups service to manage interstitial group logic, preventing their inclusion in slots and fallback groups. Updated the SlotWriter class to utilize this service, ensuring proper validation during slot creation and updates. Enhanced error handling for interstitial groups in the ImportGridCommandHandler and UpdateTemplateCommandHandler, providing warnings instead of failures when interstitials are detected. Updated related tests to verify the correct behavior of these changes, ensuring robust handling of interstitials in the scheduling process.
This commit is contained in:
Leonid Pershin
2026-07-30 12:48:51 +03:00
parent 398b60facc
commit 926a20020f
15 changed files with 370 additions and 39 deletions
@@ -2,6 +2,7 @@ using LiteCqrs;
using Microsoft.EntityFrameworkCore;
using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Common.Models;
using TeleWave.Application.Programming.Groups;
using TeleWave.Domain.Programming;
namespace TeleWave.Application.Programming.Templates.Layers;
@@ -82,8 +83,10 @@ public sealed class DeleteLayerCommandHandler(IAppDbContext dbContext)
}
}
public sealed class UpdateTemplateCommandHandler(IAppDbContext dbContext)
: ICommandHandler<UpdateTemplateCommand, Result>
public sealed class UpdateTemplateCommandHandler(
IAppDbContext dbContext,
InterstitialGroups interstitials
) : ICommandHandler<UpdateTemplateCommand, Result>
{
public async Task<Result> Handle(
UpdateTemplateCommand command,
@@ -97,11 +100,17 @@ public sealed class UpdateTemplateCommandHandler(IAppDbContext dbContext)
if (template is null)
return Result.Failure(TemplateErrors.NotFound);
if (
command.FallbackGroupId is { } groupId
&& !await dbContext.Groups.AnyAsync(g => g.Id == groupId, cancellationToken)
)
return Result.Failure(TemplateErrors.GroupNotFound);
if (command.FallbackGroupId is { } groupId)
{
if (!await dbContext.Groups.AnyAsync(g => g.Id == groupId, cancellationToken))
return Result.Failure(TemplateErrors.GroupNotFound);
// Аварийная группа закрывает каждую паузу: остаток слота, добор до якоря, пустой повтор.
// Из роликов она превращает всё это в рекламу — ровно то, что видно в расписании
// строками «аварийный запас» подряд.
if (await interstitials.IsInterstitialAsync(groupId, cancellationToken))
return Result.Failure(TemplateErrors.InterstitialFallbackGroup);
}
template.Rename(command.Name);
template.SetFallbackGroup(command.FallbackGroupId);