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,32 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetAllWeeklyPools;
/// <summary>
/// Query برای دریافت لیست تمام استخرهای کمیسیون هفتگی
/// </summary>
public record GetAllWeeklyPoolsQuery : IRequest<GetAllWeeklyPoolsResponseDto>
{
/// <summary>
/// از هفته (فیلتر اختیاری)
/// </summary>
public string? FromWeek { get; init; }
/// <summary>
/// تا هفته (فیلتر اختیاری)
/// </summary>
public string? ToWeek { get; init; }
/// <summary>
/// فقط Pool های محاسبه شده
/// </summary>
public bool? OnlyCalculated { get; init; }
/// <summary>
/// شماره صفحه
/// </summary>
public int PageIndex { get; init; } = 1;
/// <summary>
/// تعداد در صفحه
/// </summary>
public int PageSize { get; init; } = 10;
}
@@ -0,0 +1,67 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetAllWeeklyPools;
public class GetAllWeeklyPoolsQueryHandler : IRequestHandler<GetAllWeeklyPoolsQuery, GetAllWeeklyPoolsResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllWeeklyPoolsQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllWeeklyPoolsResponseDto> Handle(GetAllWeeklyPoolsQuery request, CancellationToken cancellationToken)
{
var query = _context.WeeklyCommissionPools.AsNoTracking();
// Apply filters
if (!string.IsNullOrWhiteSpace(request.FromWeek))
{
query = query.Where(x => string.Compare(x.WeekNumber, request.FromWeek) >= 0);
}
if (!string.IsNullOrWhiteSpace(request.ToWeek))
{
query = query.Where(x => string.Compare(x.WeekNumber, request.ToWeek) <= 0);
}
if (request.OnlyCalculated.HasValue && request.OnlyCalculated.Value)
{
query = query.Where(x => x.IsCalculated);
}
// Order by week number descending (newest first)
query = query.OrderByDescending(x => x.WeekNumber);
// Count total
var totalCount = await query.CountAsync(cancellationToken);
// Paginate
var pools = await query
.Skip((request.PageIndex - 1) * request.PageSize)
.Take(request.PageSize)
.Select(x => new WeeklyCommissionPoolDto
{
Id = x.Id,
WeekNumber = x.WeekNumber,
TotalPoolAmount = x.TotalPoolAmount,
TotalBalances = x.TotalBalances,
ValuePerBalance = x.ValuePerBalance,
IsCalculated = x.IsCalculated,
CalculatedAt = x.CalculatedAt,
Created = x.Created
})
.ToListAsync(cancellationToken);
return new GetAllWeeklyPoolsResponseDto
{
MetaData = new MetaDataDto
{
TotalCount = totalCount,
PageSize = request.PageSize,
CurrentPage = request.PageIndex,
TotalPages = (int)Math.Ceiling(totalCount / (double)request.PageSize)
},
Models = pools
};
}
}
@@ -0,0 +1,27 @@
namespace CMSMicroservice.Application.CommissionCQ.Queries.GetAllWeeklyPools;
public record GetAllWeeklyPoolsResponseDto
{
public MetaDataDto MetaData { get; init; } = new();
public List<WeeklyCommissionPoolDto> Models { get; init; } = new();
}
public record WeeklyCommissionPoolDto
{
public long Id { get; init; }
public string WeekNumber { get; init; } = string.Empty;
public long TotalPoolAmount { get; init; }
public int TotalBalances { get; init; }
public long ValuePerBalance { get; init; }
public bool IsCalculated { get; init; }
public DateTime? CalculatedAt { get; init; }
public DateTime Created { get; init; }
}
public record MetaDataDto
{
public int TotalCount { get; init; }
public int PageSize { get; init; }
public int CurrentPage { get; init; }
public int TotalPages { get; init; }
}