Implement billing status notification and enhance user management integration
CI / Backend (build + test) (push) Successful in 1m30s
CI / Frontend (lint + typecheck + build) (push) Successful in 33s

- Added `NotifyBillingStatusChangedAsync` method to `IRealtimeNotifier` for notifying clients about changes in billing status.
- Updated `BillingConfigResumer` to call the new notification method after modifying billing configurations, ensuring users receive real-time updates.
- Enhanced `ListUsersQueryHandler` to include a `BillingPendingReview` property in `UserSummaryDto`, indicating if a user has a pending payment request awaiting confirmation.
- Refactored various command handlers to utilize `AdvisoryLock` for managing concurrent requests, preventing race conditions in billing operations.
- Updated tests to cover new notification behaviors and ensure proper functionality in billing status management.
This commit is contained in:
Leonid Pershin
2026-07-19 23:22:57 +03:00
parent b32756d5bc
commit e19860ba46
49 changed files with 1195 additions and 233 deletions
@@ -1,10 +1,12 @@
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)
public sealed class ListUsersQueryHandler(IIdentityService identityService, IAppDbContext dbContext)
: IQueryHandler<ListUsersQuery, Result<PagedList<UserSummaryDto>>>
{
public async Task<Result<PagedList<UserSummaryDto>>> Handle(
@@ -21,6 +23,29 @@ public sealed class ListUsersQueryHandler(IIdentityService identityService)
query.Search,
cancellationToken
);
return Result.Success(result);
// 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)
);
}
}