- Introduced billing capabilities, allowing users to request payments for subscription periods (3/6/12 months) with admin approval via Telegram. - Updated role management to include a `BillingEnabled` property, preventing billing for admin roles. - Enhanced the `CreateRoleCommand` and `UpdateRoleCommand` to accept billing parameters, ensuring proper handling during role creation and updates. - Added new endpoints for billing management and integrated billing checks into VPN config creation to enforce payment requirements. - Updated related services, models, and tests to support the new billing features, ensuring comprehensive coverage and functionality. - Enhanced documentation to reflect the new billing processes and role management changes.
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Common.Messaging;
|
|
using PnvPanel.Application.Common.Models;
|
|
|
|
namespace PnvPanel.Application.Admin.Billing;
|
|
|
|
public sealed class ListPaymentRequestsQueryHandler(
|
|
IAppDbContext dbContext,
|
|
IIdentityService identityService
|
|
) : IQueryHandler<ListPaymentRequestsQuery, Result<PagedList<AdminPaymentRequestDto>>>
|
|
{
|
|
public async Task<Result<PagedList<AdminPaymentRequestDto>>> Handle(
|
|
ListPaymentRequestsQuery query,
|
|
CancellationToken cancellationToken
|
|
)
|
|
{
|
|
var page = query.Page <= 0 ? 1 : query.Page;
|
|
var pageSize = query.PageSize is <= 0 or > 100 ? 20 : query.PageSize;
|
|
|
|
var requestsQuery = dbContext.PaymentRequests.AsNoTracking();
|
|
if (query.StatusFilter is { } status)
|
|
requestsQuery = requestsQuery.Where(r => r.Status == status);
|
|
|
|
var page1 = await requestsQuery
|
|
.OrderByDescending(r => r.CreatedAt)
|
|
.ToPagedListAsync(page, pageSize, cancellationToken);
|
|
|
|
var userNames = await identityService.GetUserNamesAsync(
|
|
page1.Items.Select(r => r.UserId).Distinct().ToList(),
|
|
cancellationToken
|
|
);
|
|
|
|
var items = page1
|
|
.Items.Select(r => new AdminPaymentRequestDto(
|
|
r.Id,
|
|
r.UserId,
|
|
userNames.GetValueOrDefault(r.UserId, "?"),
|
|
r.Period,
|
|
r.AmountSnapshot,
|
|
r.Status,
|
|
r.CreatedAt
|
|
))
|
|
.ToList();
|
|
|
|
return Result.Success(
|
|
new PagedList<AdminPaymentRequestDto>(items, page1.Total, page1.Page, page1.PageSize)
|
|
);
|
|
}
|
|
}
|