Add error handling for future schedule conflicts and media asset usage
ci / build-backend (push) Successful in 2m5s
ci / build-frontend (push) Successful in 40s
ci / tests (push) Successful in 2m3s
ci / sonar (push) Successful in 7m39s

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:
Leonid Pershin
2026-07-27 02:18:25 +03:00
parent b80163b6b4
commit 2045b1a3f2
7 changed files with 288 additions and 3 deletions
@@ -20,7 +20,23 @@ public sealed class DeleteGroupCommandHandler(IAppDbContext dbContext)
if (group is null)
return Result.Failure(GroupErrors.NotFound);
// TODO(срез 1C): запретить удаление, пока на группу ссылается слот сетки.
// Слот и врезка стыка держат группу внешним ключом с Restrict — без этой проверки удаление
// упало бы исключением БД вместо управляемой ошибки. Запасная группа шаблона внешнего ключа
// не имеет, и там висячая ссылка проявилась бы только в эфире: генератор молча остался бы
// без замены для пустого слота.
var used =
await dbContext.Slots.AnyAsync(s => s.GroupId == group.Id, cancellationToken)
|| await dbContext.JunctionElements.AnyAsync(
e => e.GroupId == group.Id,
cancellationToken
)
|| await dbContext.ScheduleTemplates.AnyAsync(
t => t.FallbackGroupId == group.Id,
cancellationToken
);
if (used)
return Result.Failure(GroupErrors.InUse);
dbContext.Groups.Remove(group);
return Result.Success();
}