Add error handling for future schedule conflicts and media asset usage
Introduced new error types for handling conflicts when attempting to delete shows or media assets that are currently scheduled or in use. Updated the DeleteShowCommandHandler and DeleteMediaAssetCommandHandler to check for these conditions and return appropriate error responses. This enhances the robustness of the application by preventing unintended deletions and improving user feedback.
This commit is contained in:
@@ -21,6 +21,16 @@ public sealed class DeleteShowCommandHandler(
|
||||
if (show is null)
|
||||
return Result.Failure(ShowErrors.NotFound);
|
||||
|
||||
// Уже сгенерированный эфир ссылается на шоу без внешнего ключа: удали его — и зритель
|
||||
// получит запись без названия, а раздача упрётся в удалённые каскадом серии. Прошедшие
|
||||
// записи не держим: они лишь теряют название в EPG, а иначе шоу было бы не удалить никогда.
|
||||
var onAir = await dbContext.ScheduleEntries.AnyAsync(
|
||||
e => e.ShowId == command.ShowId && e.EndsAtUtc > DateTimeOffset.UtcNow,
|
||||
cancellationToken
|
||||
);
|
||||
if (onAir)
|
||||
return Result.Failure(ShowErrors.InFutureSchedule);
|
||||
|
||||
// Позиции коллекций уходят каскадом БД, позиции групп — вручную: ссылка группы полиморфна.
|
||||
await groupCleaner.RemoveElementAsync(
|
||||
GroupElementKind.Show,
|
||||
@@ -28,7 +38,6 @@ public sealed class DeleteShowCommandHandler(
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
// TODO(этап 2+): запретить удаление шоу, пока оно привязано к каналу или будущему расписанию.
|
||||
dbContext.Shows.Remove(show);
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ public static class ShowErrors
|
||||
"Больше одной серии бывает только у сериала."
|
||||
);
|
||||
|
||||
public static readonly Error InFutureSchedule = Error.Conflict(
|
||||
"Shows.InFutureSchedule",
|
||||
"Шоу стоит в уже сгенерированном эфире. Пересоберите расписание канала и повторите."
|
||||
);
|
||||
|
||||
public static readonly Error AssetNotFound = Error.NotFound(
|
||||
"Shows.AssetNotFound",
|
||||
"Медиа-ассет для серии не найден."
|
||||
|
||||
Reference in New Issue
Block a user