feat: add GetAvailableWeeks query and update protobuf imports
All checks were successful
Build and Deploy / build (push) Successful in 2m18s
All checks were successful
Build and Deploy / build (push) Successful in 2m18s
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace BackOffice.BFF.Application.CommissionCQ.Queries.GetAvailableWeeks;
|
||||
|
||||
public class GetAvailableWeeksQuery : IRequest<GetAvailableWeeksResponseDto>
|
||||
{
|
||||
public int FutureWeeksCount { get; init; } = 4;
|
||||
public int PastWeeksCount { get; init; } = 12;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
|
||||
using CMSMicroservice.Protobuf.Protos.Commission;
|
||||
|
||||
namespace BackOffice.BFF.Application.CommissionCQ.Queries.GetAvailableWeeks;
|
||||
|
||||
public class GetAvailableWeeksQueryHandler : IRequestHandler<GetAvailableWeeksQuery, GetAvailableWeeksResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetAvailableWeeksQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAvailableWeeksResponseDto> Handle(
|
||||
GetAvailableWeeksQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// Call CMS microservice through BFF proto
|
||||
var cmsRequest = new GetAvailableWeeksRequest
|
||||
{
|
||||
FutureWeeksCount = request.FutureWeeksCount,
|
||||
PastWeeksCount = request.PastWeeksCount
|
||||
};
|
||||
|
||||
var response = await _context.Commissions.GetAvailableWeeksAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
// Map to DTO
|
||||
return new GetAvailableWeeksResponseDto
|
||||
{
|
||||
CurrentWeek = MapToDto(response.CurrentWeek),
|
||||
CalculatedWeeks = response.CalculatedWeeks.Select(MapToDto).ToList(),
|
||||
PendingWeeks = response.PendingWeeks.Select(MapToDto).ToList(),
|
||||
FutureWeeks = response.FutureWeeks.Select(MapToDto).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private static WeekInfoDto MapToDto(WeekInfo weekInfo)
|
||||
{
|
||||
return new WeekInfoDto
|
||||
{
|
||||
WeekNumber = weekInfo.WeekNumber,
|
||||
StartDate = weekInfo.StartDate?.ToDateTime() ?? DateTime.MinValue,
|
||||
EndDate = weekInfo.EndDate?.ToDateTime() ?? DateTime.MinValue,
|
||||
IsCalculated = weekInfo.IsCalculated,
|
||||
CalculatedAt = weekInfo.CalculatedAt?.ToDateTime(),
|
||||
LastExecutionStatus = weekInfo.LastExecutionStatus,
|
||||
TotalPoolAmount = weekInfo.TotalPoolAmount != 0 ? weekInfo.TotalPoolAmount : null,
|
||||
EligibleUsersCount = weekInfo.EligibleUsersCount != 0 ? weekInfo.EligibleUsersCount : null,
|
||||
DisplayText = weekInfo.DisplayText
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace BackOffice.BFF.Application.CommissionCQ.Queries.GetAvailableWeeks;
|
||||
|
||||
public class GetAvailableWeeksResponseDto
|
||||
{
|
||||
public required WeekInfoDto CurrentWeek { get; init; }
|
||||
public required List<WeekInfoDto> CalculatedWeeks { get; init; }
|
||||
public required List<WeekInfoDto> PendingWeeks { get; init; }
|
||||
public required List<WeekInfoDto> FutureWeeks { get; init; }
|
||||
}
|
||||
|
||||
public class WeekInfoDto
|
||||
{
|
||||
public required string WeekNumber { get; init; }
|
||||
public required DateTime StartDate { get; init; }
|
||||
public required DateTime EndDate { get; init; }
|
||||
public bool IsCalculated { get; init; }
|
||||
public DateTime? CalculatedAt { get; init; }
|
||||
public string? LastExecutionStatus { get; init; }
|
||||
public long? TotalPoolAmount { get; init; }
|
||||
public int? EligibleUsersCount { get; init; }
|
||||
public required string DisplayText { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user