Refactor project files for improved readability and structure
- Cleaned up whitespace in Directory.Build.props and Directory.Packages.props for consistency. - Reformatted project file references in PnvPanel.Api.csproj for better clarity. - Enhanced code readability in various endpoint files by adjusting line breaks and indentation. - Standardized method signatures and improved formatting in ResultExtensions and multiple endpoint classes for better maintainability.
This commit is contained in:
@@ -8,28 +8,39 @@ using PnvPanel.Domain.Configs;
|
||||
namespace PnvPanel.Application.Configs.Rotate;
|
||||
|
||||
public sealed class RotateVpnConfigCommandHandler(
|
||||
IAppDbContext dbContext, IXuiPanelGateway gateway, IIdentityService identityService, ICurrentUser currentUser)
|
||||
: ICommandHandler<RotateVpnConfigCommand, Result<VpnConfigDto>>
|
||||
IAppDbContext dbContext,
|
||||
IXuiPanelGateway gateway,
|
||||
IIdentityService identityService,
|
||||
ICurrentUser currentUser
|
||||
) : ICommandHandler<RotateVpnConfigCommand, Result<VpnConfigDto>>
|
||||
{
|
||||
public async Task<Result<VpnConfigDto>> Handle(RotateVpnConfigCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<VpnConfigDto>> Handle(
|
||||
RotateVpnConfigCommand command,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId)
|
||||
return Result.Failure<VpnConfigDto>(AuthErrors.Unauthorized);
|
||||
|
||||
var config = await dbContext.VpnConfigs
|
||||
.FirstOrDefaultAsync(c => c.Id == command.ConfigId && c.UserId == userId, cancellationToken);
|
||||
var config = await dbContext.VpnConfigs.FirstOrDefaultAsync(
|
||||
c => c.Id == command.ConfigId && c.UserId == userId,
|
||||
cancellationToken
|
||||
);
|
||||
if (config is null)
|
||||
return Result.Failure<VpnConfigDto>(ConfigErrors.NotFound);
|
||||
|
||||
if (config.Status != ConfigStatus.Active)
|
||||
return Result.Failure<VpnConfigDto>(ConfigErrors.NotFound);
|
||||
|
||||
var inbound = await dbContext.Inbounds.AsNoTracking()
|
||||
var inbound = await dbContext
|
||||
.Inbounds.AsNoTracking()
|
||||
.FirstOrDefaultAsync(i => i.Id == config.InboundId, cancellationToken);
|
||||
if (inbound is null)
|
||||
return Result.Failure<VpnConfigDto>(ConfigErrors.InboundNotAvailable);
|
||||
|
||||
var node = await dbContext.Nodes.AsNoTracking().FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
|
||||
var node = await dbContext
|
||||
.Nodes.AsNoTracking()
|
||||
.FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
|
||||
if (node is null)
|
||||
return Result.Failure<VpnConfigDto>(ConfigErrors.NodeDisabled);
|
||||
|
||||
@@ -39,8 +50,14 @@ public sealed class RotateVpnConfigCommandHandler(
|
||||
|
||||
var newClientEmail = VpnConfig.GenerateClientEmail(userId);
|
||||
var addResult = await gateway.AddClientAsync(
|
||||
node, inbound.RemoteInboundId, config.Protocol, newClientEmail,
|
||||
config.Label ?? newClientEmail, profile.MaxIpLimit, cancellationToken);
|
||||
node,
|
||||
inbound.RemoteInboundId,
|
||||
config.Protocol,
|
||||
newClientEmail,
|
||||
config.Label ?? newClientEmail,
|
||||
profile.MaxIpLimit,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
if (!addResult.IsSuccess)
|
||||
return Result.Failure<VpnConfigDto>(addResult.Error);
|
||||
@@ -51,7 +68,13 @@ public sealed class RotateVpnConfigCommandHandler(
|
||||
|
||||
// Старого клиента удаляем ПОСЛЕ коммита нового состояния: если удаление не выйдет,
|
||||
// у пользователя просто останется лишний нерабочий-для-него клиент в панели — не критично.
|
||||
await gateway.RemoveClientAsync(node, inbound.RemoteInboundId, oldClientExternalId, config.Protocol, cancellationToken);
|
||||
await gateway.RemoveClientAsync(
|
||||
node,
|
||||
inbound.RemoteInboundId,
|
||||
oldClientExternalId,
|
||||
config.Protocol,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return Result.Success(VpnConfigDto.FromDomain(config, inbound));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user