feat: Implement Approve and Reject Withdrawal commands with handlers

This commit is contained in:
masoodafar-web
2025-12-01 16:48:07 +03:30
parent 8d31a8c026
commit 4aaf2247ff
27 changed files with 989 additions and 1 deletions
@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWithdrawalRequests;
public class GetWithdrawalRequestsQuery : IRequest<GetWithdrawalRequestsResponseDto>
{
public int? Status { get; set; } // CommissionPayoutStatus enum
public long? UserId { get; set; }
public string? WeekNumber { get; set; }
public PaginationState? PaginationState { get; set; }
public string? SortBy { get; set; }
}
@@ -0,0 +1,67 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWithdrawalRequests;
public class GetWithdrawalRequestsQueryHandler : IRequestHandler<GetWithdrawalRequestsQuery, GetWithdrawalRequestsResponseDto>
{
private readonly IApplicationDbContext _context;
public GetWithdrawalRequestsQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetWithdrawalRequestsResponseDto> Handle(GetWithdrawalRequestsQuery request, CancellationToken cancellationToken)
{
var query = _context.UserCommissionPayouts
.AsNoTracking()
.Include(x => x.User)
.Where(x => x.WithdrawalMethod != null) // Only requests with withdrawal method
.AsQueryable();
// Filters
if (request.Status.HasValue)
{
query = query.Where(x => (int)x.Status == request.Status.Value);
}
if (request.UserId.HasValue)
{
query = query.Where(x => x.UserId == request.UserId.Value);
}
if (!string.IsNullOrEmpty(request.WeekNumber))
{
query = query.Where(x => x.WeekNumber == request.WeekNumber);
}
query = query.ApplyOrder(sortBy: request.SortBy ?? "-Created");
var meta = await query.GetMetaData(request.PaginationState, cancellationToken);
var models = await query
.PaginatedListAsync(paginationState: request.PaginationState)
.ToListAsync(cancellationToken);
var result = models.Select(x => new WithdrawalRequestModel
{
Id = x.Id,
UserId = x.UserId,
UserName = x.User != null ? (x.User.FirstName + " " + x.User.LastName).Trim() : x.User?.Mobile ?? "N/A",
WeekNumber = x.WeekNumber,
Amount = x.TotalAmount,
Status = (int)x.Status,
WithdrawalMethod = x.WithdrawalMethod.HasValue ? (int)x.WithdrawalMethod.Value : 0,
IbanNumber = x.IbanNumber,
RequestedAt = x.WithdrawnAt ?? x.Created,
ProcessedAt = x.LastModified,
ProcessedBy = null, // TODO: Add admin user tracking
Reason = null, // TODO: Add rejection reason field
Created = x.Created
}).ToList();
return new GetWithdrawalRequestsResponseDto
{
MetaData = meta,
Models = result
};
}
}
@@ -0,0 +1,24 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWithdrawalRequests;
public class GetWithdrawalRequestsResponseDto
{
public MetaData? MetaData { get; set; }
public List<WithdrawalRequestModel> Models { get; set; } = new();
}
public class WithdrawalRequestModel
{
public long Id { get; set; }
public long UserId { get; set; }
public string UserName { get; set; } = string.Empty;
public string WeekNumber { get; set; } = string.Empty;
public long Amount { get; set; }
public int Status { get; set; } // CommissionPayoutStatus enum
public int? WithdrawalMethod { get; set; }
public string? IbanNumber { get; set; }
public DateTime? RequestedAt { get; set; }
public DateTime? ProcessedAt { get; set; }
public string? ProcessedBy { get; set; }
public string? Reason { get; set; }
public DateTime Created { get; set; }
}