feat: refactor week number handling to use WeekDefinitionId across multiple entities and queries
This commit is contained in:
+1
-1
@@ -8,5 +8,5 @@ public record GetWeeklyCommissionPoolQuery : IRequest<WeeklyCommissionPoolDto?>
|
||||
/// <summary>
|
||||
/// شماره هفته
|
||||
/// </summary>
|
||||
public string WeekNumber { get; init; } = string.Empty;
|
||||
public long WeekDefinitionId { get; init; }
|
||||
}
|
||||
|
||||
+16
-5
@@ -3,21 +3,27 @@ namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWeeklyCommissionPo
|
||||
public class GetWeeklyCommissionPoolQueryHandler : IRequestHandler<GetWeeklyCommissionPoolQuery, WeeklyCommissionPoolDto?>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IWeekDefinitionRepository _weekDefinitionRepository;
|
||||
|
||||
public GetWeeklyCommissionPoolQueryHandler(IApplicationDbContext context)
|
||||
public GetWeeklyCommissionPoolQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
IWeekDefinitionRepository weekDefinitionRepository)
|
||||
{
|
||||
_context = context;
|
||||
_weekDefinitionRepository = weekDefinitionRepository;
|
||||
}
|
||||
|
||||
public async Task<WeeklyCommissionPoolDto?> Handle(GetWeeklyCommissionPoolQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = await _context.WeeklyCommissionPools
|
||||
var pool = await _context.WeeklyCommissionPools
|
||||
.Include(x => x.WeekDefinition)
|
||||
.AsNoTracking()
|
||||
.Where(x => x.WeekNumber == request.WeekNumber)
|
||||
.Where(x => x.WeekDefinitionId == request.WeekDefinitionId)
|
||||
.Select(x => new WeeklyCommissionPoolDto
|
||||
{
|
||||
Id = x.Id,
|
||||
WeekNumber = x.WeekNumber,
|
||||
WeekDefinitionId = x.WeekDefinitionId,
|
||||
WeekDisplayName=x.WeekDefinition.DisplayName,
|
||||
TotalPoolAmount = x.TotalPoolAmount,
|
||||
TotalBalances = x.TotalBalances,
|
||||
ValuePerBalance = x.ValuePerBalance,
|
||||
@@ -27,6 +33,11 @@ public class GetWeeklyCommissionPoolQueryHandler : IRequestHandler<GetWeeklyComm
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return pool??new WeeklyCommissionPoolDto();
|
||||
// if (pool != null)
|
||||
// {
|
||||
// pool.WeekDisplayName = _weekDefinitionRepository.GetDisplayNameByGregorianWeekNumber(pool.WeekNumber);
|
||||
// }
|
||||
|
||||
return pool ?? new WeeklyCommissionPoolDto();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -4,11 +4,9 @@ public class GetWeeklyCommissionPoolQueryValidator : AbstractValidator<GetWeekly
|
||||
{
|
||||
public GetWeeklyCommissionPoolQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.WeekNumber)
|
||||
.NotEmpty()
|
||||
.WithMessage("شماره هفته نمیتواند خالی باشد")
|
||||
.Matches(@"^\d{4}-W\d{2}$")
|
||||
.WithMessage("فرمت شماره هفته باید YYYY-Www باشد");
|
||||
RuleFor(x => x.WeekDefinitionId)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("شماره هفته نمیتواند صفر باشد");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@ namespace CMSMicroservice.Application.CommissionCQ.Queries.GetWeeklyCommissionPo
|
||||
public class WeeklyCommissionPoolDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string WeekNumber { get; set; } = string.Empty;
|
||||
public long WeekDefinitionId { get; set; }
|
||||
public string WeekDisplayName { get; set; } = string.Empty;
|
||||
public long TotalPoolAmount { get; set; }
|
||||
public long TotalBalances { get; set; }
|
||||
public decimal ValuePerBalance { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user