feat: refactor week number handling to use WeekDefinitionId across multiple entities and queries
This commit is contained in:
+2
-2
@@ -8,12 +8,12 @@ public record GetAllWeeklyPoolsQuery : IRequest<GetAllWeeklyPoolsResponseDto>
|
||||
/// <summary>
|
||||
/// از هفته (فیلتر اختیاری)
|
||||
/// </summary>
|
||||
public string? FromWeek { get; init; }
|
||||
public int? FromWeekOrder { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// تا هفته (فیلتر اختیاری)
|
||||
/// </summary>
|
||||
public string? ToWeek { get; init; }
|
||||
public int? ToWeekOrder { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// فقط Pool های محاسبه شده
|
||||
|
||||
+28
-8
@@ -3,25 +3,31 @@ namespace CMSMicroservice.Application.CommissionCQ.Queries.GetAllWeeklyPools;
|
||||
public class GetAllWeeklyPoolsQueryHandler : IRequestHandler<GetAllWeeklyPoolsQuery, GetAllWeeklyPoolsResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IWeekDefinitionRepository _weekDefinitionRepository;
|
||||
|
||||
public GetAllWeeklyPoolsQueryHandler(IApplicationDbContext context)
|
||||
public GetAllWeeklyPoolsQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
IWeekDefinitionRepository weekDefinitionRepository)
|
||||
{
|
||||
_context = context;
|
||||
_weekDefinitionRepository = weekDefinitionRepository;
|
||||
}
|
||||
|
||||
public async Task<GetAllWeeklyPoolsResponseDto> Handle(GetAllWeeklyPoolsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.WeeklyCommissionPools.AsNoTracking();
|
||||
var query = _context.WeeklyCommissionPools
|
||||
.Include(i=> i.WeekDefinition)
|
||||
.AsNoTracking();
|
||||
|
||||
// Apply filters
|
||||
if (!string.IsNullOrWhiteSpace(request.FromWeek))
|
||||
if (request.FromWeekOrder!=null)
|
||||
{
|
||||
query = query.Where(x => string.Compare(x.WeekNumber, request.FromWeek) >= 0);
|
||||
query = query.Where(x => x.WeekDefinition.WeekOrder>=request.FromWeekOrder );
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.ToWeek))
|
||||
if (request.ToWeekOrder!=null)
|
||||
{
|
||||
query = query.Where(x => string.Compare(x.WeekNumber, request.ToWeek) <= 0);
|
||||
query = query.Where(x =>x.WeekDefinition.WeekOrder<= request.ToWeekOrder);
|
||||
}
|
||||
|
||||
if (request.OnlyCalculated.HasValue && request.OnlyCalculated.Value)
|
||||
@@ -30,7 +36,7 @@ public class GetAllWeeklyPoolsQueryHandler : IRequestHandler<GetAllWeeklyPoolsQu
|
||||
}
|
||||
|
||||
// Order by week number descending (newest first)
|
||||
query = query.OrderByDescending(x => x.WeekNumber);
|
||||
query = query.OrderByDescending(x => x.WeekDefinitionId);
|
||||
|
||||
// Count total
|
||||
var totalCount = await query.CountAsync(cancellationToken);
|
||||
@@ -42,7 +48,8 @@ public class GetAllWeeklyPoolsQueryHandler : IRequestHandler<GetAllWeeklyPoolsQu
|
||||
.Select(x => new WeeklyCommissionPoolDto
|
||||
{
|
||||
Id = x.Id,
|
||||
WeekNumber = x.WeekNumber,
|
||||
WeekDefinitionId = x.WeekDefinitionId,
|
||||
WeekDisplayName = x.WeekDefinition.PersianWeekNumber,
|
||||
TotalPoolAmount = x.TotalPoolAmount,
|
||||
TotalBalances = x.TotalBalances,
|
||||
ValuePerBalance = x.ValuePerBalance,
|
||||
@@ -52,6 +59,19 @@ public class GetAllWeeklyPoolsQueryHandler : IRequestHandler<GetAllWeeklyPoolsQu
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
// Populate WeekDisplayName from cache
|
||||
// foreach (var pool in pools)
|
||||
// {
|
||||
// // WeeklyCommissionPoolDto is a record, need to create new instance with display name
|
||||
// // Since records are immutable, we can't modify them directly
|
||||
// }
|
||||
|
||||
// // Create new list with WeekDisplayName populated
|
||||
// var poolsWithDisplayName = pools.Select(p => p with
|
||||
// {
|
||||
// WeekDisplayName = _weekDefinitionRepository.GetDisplayNameByGregorianWeekNumber(p.WeekNumber)
|
||||
// }).ToList();
|
||||
|
||||
return new GetAllWeeklyPoolsResponseDto
|
||||
{
|
||||
MetaData = new MetaDataDto
|
||||
|
||||
+2
-1
@@ -9,7 +9,8 @@ public record GetAllWeeklyPoolsResponseDto
|
||||
public record WeeklyCommissionPoolDto
|
||||
{
|
||||
public long Id { get; init; }
|
||||
public string WeekNumber { get; init; } = string.Empty;
|
||||
public long WeekDefinitionId { get; init; }
|
||||
public string WeekDisplayName { get; init; } = string.Empty;
|
||||
public long TotalPoolAmount { get; init; }
|
||||
public int TotalBalances { get; init; }
|
||||
public long ValuePerBalance { get; init; }
|
||||
|
||||
Reference in New Issue
Block a user