Files
PnvPanel/backend/src/PnvPanel.Application/Admin/Users/ListUsersQueryHandler.cs
T
Leonid Pershin 33ad98cf62
CI / Backend (build + test) (push) Successful in 1m22s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s
Enhance admin endpoints and queries for improved filtering and management
- Updated `ListPaymentRequestsQuery` to include `Kind` and `Search` parameters for better filtering of payment requests.
- Enhanced `ListAuditLogsQuery` to support additional filters: `Source`, `TargetType`, and `Action`, improving audit log retrieval.
- Modified `ListUsersQuery` to accept new filters: `RoleId`, `IsActivated`, `IsBlocked`, and `BillingExpired`, allowing for more granular user management.
- Introduced `DeleteInbound` endpoint to allow deletion of inbounds that are not currently available, enhancing inbound management capabilities.
- Updated frontend API calls to reflect new query parameters and support for additional filtering options in the admin interface.
- Revised API documentation to include new parameters and endpoint functionalities for better clarity and usage guidance.
2026-07-20 10:35:48 +03:00

56 lines
2.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
using PnvPanel.Application.Common.Models;
using PnvPanel.Domain.Billing;
namespace PnvPanel.Application.Admin.Users;
public sealed class ListUsersQueryHandler(IIdentityService identityService, IAppDbContext dbContext)
: IQueryHandler<ListUsersQuery, Result<PagedList<UserSummaryDto>>>
{
public async Task<Result<PagedList<UserSummaryDto>>> Handle(
ListUsersQuery query,
CancellationToken cancellationToken
)
{
var page = query.Page <= 0 ? 1 : query.Page;
var pageSize = query.PageSize is <= 0 or > 100 ? 20 : query.PageSize;
var result = await identityService.ListUsersAsync(
page,
pageSize,
query.Search,
query.RoleId,
query.IsActivated,
query.IsBlocked,
query.BillingExpired,
cancellationToken
);
// IIdentityService ничего не знает про PaymentRequests (Identity не должен на них ссылаться) —
// подмешиваем "заявка на проверке" здесь, чтобы админский список видел ту же защиту от
// тревожного "Истекло", что уже показывается пользователю на /billing (PaidUntilBadge.pendingReview).
var userIds = result.Items.Select(u => u.Id).ToList();
var pendingUserIds = await dbContext
.PaymentRequests.Where(r =>
userIds.Contains(r.UserId)
&& r.Kind == PaymentRequestKind.Subscription
&& r.Status == PaymentRequestStatus.AwaitingConfirmation
)
.Select(r => r.UserId)
.ToListAsync(cancellationToken);
if (pendingUserIds.Count == 0)
return Result.Success(result);
var pendingSet = pendingUserIds.ToHashSet();
var enrichedItems = result
.Items.Select(u => pendingSet.Contains(u.Id) ? u with { BillingPendingReview = true } : u)
.ToList();
return Result.Success(
new PagedList<UserSummaryDto>(enrichedItems, result.Total, result.Page, result.PageSize)
);
}
}