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:
@@ -4,12 +4,18 @@ namespace PnvPanel.Application.Activation;
|
||||
|
||||
public static class ActivationErrors
|
||||
{
|
||||
public static readonly Error AlreadyPending =
|
||||
Error.Conflict("Activation.AlreadyPending", "У вас уже есть необработанный запрос на активацию.");
|
||||
public static readonly Error AlreadyPending = Error.Conflict(
|
||||
"Activation.AlreadyPending",
|
||||
"У вас уже есть необработанный запрос на активацию."
|
||||
);
|
||||
|
||||
public static readonly Error NotFound =
|
||||
Error.NotFound("Activation.NotFound", "Запрос на активацию не найден.");
|
||||
public static readonly Error NotFound = Error.NotFound(
|
||||
"Activation.NotFound",
|
||||
"Запрос на активацию не найден."
|
||||
);
|
||||
|
||||
public static readonly Error AlreadyDecided =
|
||||
Error.Conflict("Activation.AlreadyDecided", "Запрос на активацию уже обработан.");
|
||||
public static readonly Error AlreadyDecided = Error.Conflict(
|
||||
"Activation.AlreadyDecided",
|
||||
"Запрос на активацию уже обработан."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,16 @@ using PnvPanel.Domain.Activation;
|
||||
|
||||
namespace PnvPanel.Application.Activation;
|
||||
|
||||
public sealed class GetActivationStatusQueryHandler(IIdentityService identityService, IAppDbContext dbContext, ICurrentUser currentUser)
|
||||
: IQueryHandler<GetActivationStatusQuery, Result<ActivationStatusDto>>
|
||||
public sealed class GetActivationStatusQueryHandler(
|
||||
IIdentityService identityService,
|
||||
IAppDbContext dbContext,
|
||||
ICurrentUser currentUser
|
||||
) : IQueryHandler<GetActivationStatusQuery, Result<ActivationStatusDto>>
|
||||
{
|
||||
public async Task<Result<ActivationStatusDto>> Handle(GetActivationStatusQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<ActivationStatusDto>> Handle(
|
||||
GetActivationStatusQuery query,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId)
|
||||
return Result.Failure<ActivationStatusDto>(AuthErrors.Unauthorized);
|
||||
@@ -19,8 +25,10 @@ public sealed class GetActivationStatusQueryHandler(IIdentityService identitySer
|
||||
if (profile is null)
|
||||
return Result.Failure<ActivationStatusDto>(AuthErrors.Unauthorized);
|
||||
|
||||
var pending = await dbContext.ActivationRequests
|
||||
.Where(r => r.UserId == userId && r.Status == ActivationStatus.Pending)
|
||||
var pending = await dbContext
|
||||
.ActivationRequests.Where(r =>
|
||||
r.UserId == userId && r.Status == ActivationStatus.Pending
|
||||
)
|
||||
.Select(r => new ActivationRequestDto(r.Id, r.Comment, r.CreatedAt))
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@ using PnvPanel.Application.Common.Models;
|
||||
|
||||
namespace PnvPanel.Application.Activation;
|
||||
|
||||
public sealed record RequestActivationCommand(string? Comment) : ICommand<Result<ActivationRequestDto>>;
|
||||
public sealed record RequestActivationCommand(string? Comment)
|
||||
: ICommand<Result<ActivationRequestDto>>;
|
||||
|
||||
@@ -8,16 +8,24 @@ using PnvPanel.Domain.Activation;
|
||||
namespace PnvPanel.Application.Activation;
|
||||
|
||||
public sealed class RequestActivationCommandHandler(
|
||||
IAppDbContext dbContext, IRealtimeNotifier notifier, ITelegramNotifier telegramNotifier, ICurrentUser currentUser)
|
||||
: ICommandHandler<RequestActivationCommand, Result<ActivationRequestDto>>
|
||||
IAppDbContext dbContext,
|
||||
IRealtimeNotifier notifier,
|
||||
ITelegramNotifier telegramNotifier,
|
||||
ICurrentUser currentUser
|
||||
) : ICommandHandler<RequestActivationCommand, Result<ActivationRequestDto>>
|
||||
{
|
||||
public async Task<Result<ActivationRequestDto>> Handle(RequestActivationCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<ActivationRequestDto>> Handle(
|
||||
RequestActivationCommand command,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
if (currentUser.UserId is not { } userId)
|
||||
return Result.Failure<ActivationRequestDto>(AuthErrors.Unauthorized);
|
||||
|
||||
var hasPending = await dbContext.ActivationRequests
|
||||
.AnyAsync(r => r.UserId == userId && r.Status == ActivationStatus.Pending, cancellationToken);
|
||||
var hasPending = await dbContext.ActivationRequests.AnyAsync(
|
||||
r => r.UserId == userId && r.Status == ActivationStatus.Pending,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
if (hasPending)
|
||||
return Result.Failure<ActivationRequestDto>(ActivationErrors.AlreadyPending);
|
||||
@@ -27,9 +35,23 @@ public sealed class RequestActivationCommandHandler(
|
||||
|
||||
var userName = currentUser.UserName ?? userId.ToString();
|
||||
|
||||
await notifier.NotifyActivationRequestedAsync(request.Id, userId, userName, request.Comment, request.CreatedAt, cancellationToken);
|
||||
await telegramNotifier.NotifyAdminsActivationRequestedAsync(request.Id, userName, request.Comment, cancellationToken);
|
||||
await notifier.NotifyActivationRequestedAsync(
|
||||
request.Id,
|
||||
userId,
|
||||
userName,
|
||||
request.Comment,
|
||||
request.CreatedAt,
|
||||
cancellationToken
|
||||
);
|
||||
await telegramNotifier.NotifyAdminsActivationRequestedAsync(
|
||||
request.Id,
|
||||
userName,
|
||||
request.Comment,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return Result.Success(new ActivationRequestDto(request.Id, request.Comment, request.CreatedAt));
|
||||
return Result.Success(
|
||||
new ActivationRequestDto(request.Id, request.Comment, request.CreatedAt)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user