Added new BumperEndpoints to the API for managing bumper templates and variants, enhancing the channel management capabilities. Removed outdated bumper-related commands and handlers from the application, streamlining the codebase and improving maintainability. Updated ChannelEndpoints to reflect these changes and ensure proper routing for the new endpoints.
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using LiteCqrs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TeleWave.Application.Common.Interfaces;
|
|
using TeleWave.Application.Common.Models;
|
|
|
|
namespace TeleWave.Application.Programming.Templates.Junctions;
|
|
|
|
public sealed class DeleteJunctionCommandHandler(IAppDbContext dbContext)
|
|
: ICommandHandler<DeleteJunctionCommand, Result>
|
|
{
|
|
public async Task<Result> Handle(
|
|
DeleteJunctionCommand command,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var junction = await JunctionLoader.LoadAsync(
|
|
dbContext,
|
|
command.JunctionId,
|
|
cancellationToken
|
|
);
|
|
if (junction is null)
|
|
return Result.Failure(TemplateErrors.JunctionNotFound);
|
|
|
|
// Стык общий: слот чужого канала, ссылающийся на удалённый стык, молча остался бы без врезок.
|
|
var usedBySlot = await dbContext.Slots.AnyAsync(
|
|
s => s.JunctionBetweenId == junction.Id || s.JunctionAfterId == junction.Id,
|
|
cancellationToken
|
|
);
|
|
var usedByDefault = await dbContext.ScheduleTemplates.AnyAsync(
|
|
t => t.DefaultJunctionId == junction.Id,
|
|
cancellationToken
|
|
);
|
|
if (usedBySlot || usedByDefault)
|
|
return Result.Failure(TemplateErrors.JunctionInUse);
|
|
|
|
dbContext.JunctionTemplates.Remove(junction);
|
|
return Result.Success();
|
|
}
|
|
}
|