feat: refactor week number handling to use WeekDefinitionId across multiple entities and queries
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ public record GetUserCommissionPayoutsQuery : IRequest<GetUserCommissionPayoutsR
|
||||
/// <summary>
|
||||
/// شماره هفته (اختیاری)
|
||||
/// </summary>
|
||||
public string? WeekNumber { get; init; }
|
||||
public long? WeekDefinitionId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// مرتبسازی
|
||||
|
||||
+16
-4
@@ -3,15 +3,20 @@ namespace CMSMicroservice.Application.CommissionCQ.Queries.GetUserCommissionPayo
|
||||
public class GetUserCommissionPayoutsQueryHandler : IRequestHandler<GetUserCommissionPayoutsQuery, GetUserCommissionPayoutsResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IWeekDefinitionRepository _weekDefinitionRepository;
|
||||
|
||||
public GetUserCommissionPayoutsQueryHandler(IApplicationDbContext context)
|
||||
public GetUserCommissionPayoutsQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
IWeekDefinitionRepository weekDefinitionRepository)
|
||||
{
|
||||
_context = context;
|
||||
_weekDefinitionRepository = weekDefinitionRepository;
|
||||
}
|
||||
|
||||
public async Task<GetUserCommissionPayoutsResponseDto> Handle(GetUserCommissionPayoutsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.UserCommissionPayouts
|
||||
.Include(x => x.WeekDefinition)
|
||||
.Include(x => x.User)
|
||||
.AsNoTracking()
|
||||
.AsQueryable();
|
||||
@@ -27,9 +32,9 @@ public class GetUserCommissionPayoutsQueryHandler : IRequestHandler<GetUserCommi
|
||||
query = query.Where(x => x.Status == request.Status.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.WeekNumber))
|
||||
if (request.WeekDefinitionId!=null)
|
||||
{
|
||||
query = query.Where(x => x.WeekNumber == request.WeekNumber);
|
||||
query = query.Where(x => x.WeekDefinitionId == request.WeekDefinitionId);
|
||||
}
|
||||
|
||||
query = query.ApplyOrder(sortBy: request.SortBy ?? "Created");
|
||||
@@ -44,7 +49,8 @@ public class GetUserCommissionPayoutsQueryHandler : IRequestHandler<GetUserCommi
|
||||
UserId = x.UserId,
|
||||
FirstName = x.User.FirstName,
|
||||
LastName = x.User.LastName,
|
||||
WeekNumber = x.WeekNumber,
|
||||
WeekDefinitionId = x.WeekDefinitionId,
|
||||
WeekDisplayName = x.WeekDefinition != null ? x.WeekDefinition.DisplayName : "",
|
||||
WeeklyPoolId = x.WeeklyPoolId,
|
||||
BalancesEarned = x.BalancesEarned,
|
||||
ValuePerBalance = x.ValuePerBalance,
|
||||
@@ -58,6 +64,12 @@ public class GetUserCommissionPayoutsQueryHandler : IRequestHandler<GetUserCommi
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
// // Populate WeekDisplayName from cache
|
||||
// foreach (var model in models)
|
||||
// {
|
||||
// model.WeekDisplayName = _weekDefinitionRepository.GetDisplayNameByGregorianWeekNumber(model.WeekNumber);
|
||||
// }
|
||||
|
||||
return new GetUserCommissionPayoutsResponseDto
|
||||
{
|
||||
MetaData = meta,
|
||||
|
||||
+4
-4
@@ -14,10 +14,10 @@ public class GetUserCommissionPayoutsQueryValidator : AbstractValidator<GetUserC
|
||||
.WithMessage("وضعیت معتبر نیست")
|
||||
.When(x => x.Status.HasValue);
|
||||
|
||||
RuleFor(x => x.WeekNumber)
|
||||
.Matches(@"^\d{4}-W\d{2}$")
|
||||
.WithMessage("فرمت شماره هفته باید YYYY-Www باشد")
|
||||
.When(x => !string.IsNullOrEmpty(x.WeekNumber));
|
||||
RuleFor(x => x.WeekDefinitionId)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("شماره هفته نمیتواند صفر باشد")
|
||||
.When(x => x.WeekDefinitionId.HasValue);
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
|
||||
+2
-1
@@ -12,7 +12,8 @@ public class GetUserCommissionPayoutsResponseModel
|
||||
public long UserId { get; set; }
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
public string WeekNumber { get; set; } = string.Empty;
|
||||
public long WeekDefinitionId { get; set; }
|
||||
public string WeekDisplayName { get; set; } = string.Empty;
|
||||
public long WeeklyPoolId { get; set; }
|
||||
public long BalancesEarned { get; set; }
|
||||
public decimal ValuePerBalance { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user