using Microsoft.EntityFrameworkCore; using PnvPanel.Application.Common.Interfaces; using PnvPanel.Application.Common.Messaging; using PnvPanel.Application.Common.Models; namespace PnvPanel.Application.Admin.Nodes; public sealed class DeleteNodeCommandHandler(IAppDbContext dbContext, IXuiPanelGateway gateway) : ICommandHandler { public async Task Handle(DeleteNodeCommand command, CancellationToken cancellationToken) { var node = await dbContext.Nodes.FirstOrDefaultAsync(n => n.Id == command.NodeId, cancellationToken); if (node is null) return Result.Failure(NodeErrors.NotFound); var inbounds = await dbContext.Inbounds.Where(i => i.NodeId == node.Id).ToListAsync(cancellationToken); dbContext.Inbounds.RemoveRange(inbounds); dbContext.Nodes.Remove(node); gateway.InvalidateClient(node.Id); return Result.Success(); } }