feat: add GetWeekDefinitions RPC and corresponding query handler for week retrieval
This commit is contained in:
+2
-2
@@ -6,9 +6,9 @@ namespace FrontOffice.BFF.Application.CommissionCQ.Queries.GetMyCommissionPayout
|
||||
public record GetMyCommissionPayoutsQuery : IRequest<GetMyCommissionPayoutsResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// شماره هفته در فرمت ISO (مثال: "2025-W48"، null = همه)
|
||||
/// شناسه تعریف هفته (null = همه)
|
||||
/// </summary>
|
||||
public string? WeekNumber { get; init; }
|
||||
public long? WeekDefinitionId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// وضعیت: 0=Pending, 1=Calculated, 2=Paid, 3=Withdrawn (null = همه)
|
||||
|
||||
+4
-4
@@ -28,8 +28,8 @@ public class GetMyCommissionPayoutsQueryHandler : IRequestHandler<GetMyCommissio
|
||||
};
|
||||
|
||||
// WeekNumber is string type in proto - assign directly
|
||||
if (!string.IsNullOrEmpty(request.WeekNumber))
|
||||
cmsRequest.WeekNumber = request.WeekNumber;
|
||||
if (request.WeekDefinitionId!=null)
|
||||
cmsRequest.WeekDefinitionId = request.WeekDefinitionId;
|
||||
|
||||
if (request.Status.HasValue)
|
||||
cmsRequest.Status = request.Status.Value; // int? type in proto
|
||||
@@ -39,8 +39,8 @@ public class GetMyCommissionPayoutsQueryHandler : IRequestHandler<GetMyCommissio
|
||||
var payouts = response.Models.Select(p => new CommissionPayoutDto
|
||||
{
|
||||
Id = p.Id,
|
||||
WeekNumber = p.WeekNumber,
|
||||
WeekLabel = $"هفته {p.WeekNumber}",
|
||||
WeekDefinitionId = p.WeekDefinitionId,
|
||||
WeekDisplayName = p.WeekDisplayName,
|
||||
BalancesEarned = (int)p.BalancesEarned,
|
||||
TotalAmount = p.TotalAmount,
|
||||
AmountFormatted = FormatCurrency(p.TotalAmount),
|
||||
|
||||
+4
-4
@@ -16,14 +16,14 @@ public class CommissionPayoutDto
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شماره هفته (e.g., "2024-W45")
|
||||
/// شناسه تعریف هفته
|
||||
/// </summary>
|
||||
public string WeekNumber { get; set; } = string.Empty;
|
||||
public long WeekDefinitionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// لیبل هفته (هفته 45 - آذر 1403)
|
||||
/// نام نمایشی هفته (هفته 45 - آذر 1403)
|
||||
/// </summary>
|
||||
public string WeekLabel { get; set; } = string.Empty;
|
||||
public string WeekDisplayName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// تعداد Balance کسب شده
|
||||
|
||||
+2
-2
@@ -6,9 +6,9 @@ namespace FrontOffice.BFF.Application.CommissionCQ.Queries.GetMyWeeklyBalances;
|
||||
public record GetMyWeeklyBalancesQuery : IRequest<GetMyWeeklyBalancesResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// شماره هفته در فرمت ISO (مثال: "2025-W48"، null = هفته جاری)
|
||||
/// شناسه تعریف هفته (null = همه هفتهها)
|
||||
/// </summary>
|
||||
public string? WeekNumber { get; init; }
|
||||
public long? WeekDefinitionId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// فقط تعادلهای فعال (غیر منقضی)
|
||||
|
||||
+4
-3
@@ -29,8 +29,8 @@ public class GetMyWeeklyBalancesQueryHandler : IRequestHandler<GetMyWeeklyBalanc
|
||||
};
|
||||
|
||||
// WeekNumber is string in proto (format: "YYYY-Www")
|
||||
if (!string.IsNullOrEmpty(request.WeekNumber))
|
||||
cmsRequest.WeekNumber = request.WeekNumber;
|
||||
if (request.WeekDefinitionId!=null && request.WeekDefinitionId>0)
|
||||
cmsRequest.WeekDefinitionId = request.WeekDefinitionId;
|
||||
|
||||
var response = await _context.Commission.GetUserWeeklyBalancesAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
@@ -38,7 +38,8 @@ public class GetMyWeeklyBalancesQueryHandler : IRequestHandler<GetMyWeeklyBalanc
|
||||
var balances = response.Models.Select(b => new WeeklyBalanceItemDto
|
||||
{
|
||||
Id = b.Id,
|
||||
WeekNumber = b.WeekNumber,
|
||||
WeekDefinitionId = b.WeekDefinitionId,
|
||||
WeekLabel = b.WeekDisplayName,
|
||||
LeftLegBalances = b.LeftLegBalances,
|
||||
RightLegBalances = b.RightLegBalances,
|
||||
TotalBalances = b.TotalBalances,
|
||||
|
||||
+7
-2
@@ -46,9 +46,14 @@ public class WeeklyBalanceItemDto
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// شماره هفته (فرمت: "2025-W48")
|
||||
/// شناسه تعریف هفته
|
||||
/// </summary>
|
||||
public string WeekNumber { get; set; } = string.Empty;
|
||||
public long WeekDefinitionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// برچسب هفته (مثال: "هفته اول")
|
||||
/// </summary>
|
||||
public string WeekLabel { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// تعادل پای چپ
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
namespace FrontOffice.BFF.Application.CommissionCQ.Queries.GetWeekDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست هفتهها برای dropdown
|
||||
/// </summary>
|
||||
public record GetWeekDefinitionsQuery : IRequest<GetWeekDefinitionsResponseDto>
|
||||
{
|
||||
//جستجوی متنی روی DisplayName
|
||||
public string? SearchText { get; init; }
|
||||
|
||||
//شماره صفحه
|
||||
public int PageNumber { get; init; } = 1;
|
||||
|
||||
//تعداد در صفحه
|
||||
public int PageSize { get; init; } = 100;
|
||||
|
||||
//سال میلادی
|
||||
public int? GregorianYear { get; init; }
|
||||
|
||||
//سال شمسی
|
||||
public int? PersianYear { get; init; }
|
||||
|
||||
//فقط هفتههای فعال
|
||||
public bool? IsActive { get; init; }
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Commission;
|
||||
using FrontOffice.BFF.Application.Common.Models;
|
||||
|
||||
namespace FrontOffice.BFF.Application.CommissionCQ.Queries.GetWeekDefinitions;
|
||||
|
||||
public class GetWeekDefinitionsQueryHandler : IRequestHandler<GetWeekDefinitionsQuery, GetWeekDefinitionsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetWeekDefinitionsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetWeekDefinitionsResponseDto> Handle(GetWeekDefinitionsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// ساخت درخواست به CMS
|
||||
var cmsRequest = new GetWeekDefinitionsRequest
|
||||
{
|
||||
PaginationState = new CMSMicroservice.Protobuf.Protos.PaginationState
|
||||
{
|
||||
PageNumber = request.PageNumber,
|
||||
PageSize = request.PageSize
|
||||
}
|
||||
};
|
||||
|
||||
// اعمال فیلتر
|
||||
var filter = new GetWeekDefinitionsFilter();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.SearchText))
|
||||
filter.SearchText = request.SearchText;
|
||||
|
||||
if (request.GregorianYear.HasValue)
|
||||
filter.GregorianYear = request.GregorianYear.Value;
|
||||
|
||||
if (request.PersianYear.HasValue)
|
||||
filter.PersianYear = request.PersianYear.Value;
|
||||
|
||||
if (request.IsActive.HasValue)
|
||||
filter.IsActive = request.IsActive.Value;
|
||||
|
||||
cmsRequest.Filter = filter;
|
||||
|
||||
// فراخوانی CMS
|
||||
var response = await _context.Commission.GetWeekDefinitionsAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
// تبدیل به DTO
|
||||
var weeks = response.Data.Select(w => new WeekDefinitionDto
|
||||
{
|
||||
Id = w.Id,
|
||||
WeekOrder = w.WeekOrder,
|
||||
DisplayName = w.DisplayName,
|
||||
GregorianWeekNumber = w.GregorianWeekNumber,
|
||||
PersianWeekNumber = w.PersianWeekNumber,
|
||||
StartDate = w.StartDate?.ToDateTime() ?? DateTime.MinValue,
|
||||
EndDate = w.EndDate?.ToDateTime() ?? DateTime.MinValue,
|
||||
GregorianYear = w.GregorianYear,
|
||||
PersianYear = w.PersianYear,
|
||||
IsActive = w.IsActive,
|
||||
IsCurrentWeek = w.IsCurrentWeek,
|
||||
StartDatePersian = FormatPersianDate(w.StartDate?.ToDateTime()),
|
||||
EndDatePersian = FormatPersianDate(w.EndDate?.ToDateTime())
|
||||
}).ToList();
|
||||
|
||||
return new GetWeekDefinitionsResponseDto
|
||||
{
|
||||
Data = weeks,
|
||||
TotalCount = response.TotalCount
|
||||
};
|
||||
}
|
||||
|
||||
private static string FormatPersianDate(DateTime? date)
|
||||
{
|
||||
if (!date.HasValue) return string.Empty;
|
||||
// TODO: استفاده از PersianCalendar
|
||||
return date.Value.ToString("yyyy/MM/dd");
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
namespace FrontOffice.BFF.Application.CommissionCQ.Queries.GetWeekDefinitions;
|
||||
|
||||
/// <summary>
|
||||
/// پاسخ لیست هفتهها
|
||||
/// </summary>
|
||||
public class GetWeekDefinitionsResponseDto
|
||||
{
|
||||
//لیست هفتهها
|
||||
public List<WeekDefinitionDto> Data { get; set; } = new();
|
||||
|
||||
//تعداد کل
|
||||
public int TotalCount { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// آیتم هفته برای dropdown
|
||||
/// </summary>
|
||||
public class WeekDefinitionDto
|
||||
{
|
||||
//شناسه تعریف هفته
|
||||
public long Id { get; set; }
|
||||
|
||||
//شماره ترتیب هفته (1, 2, 3, ...)
|
||||
public int WeekOrder { get; set; }
|
||||
|
||||
//نام نمایشی هفته (هفته یکم، هفته دوم، ...)
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
|
||||
//شماره هفته میلادی (2025-W46)
|
||||
public string GregorianWeekNumber { get; set; } = string.Empty;
|
||||
|
||||
//شماره هفته شمسی (1404-W35)
|
||||
public string PersianWeekNumber { get; set; } = string.Empty;
|
||||
|
||||
//تاریخ شروع هفته
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
//تاریخ پایان هفته
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
//سال میلادی
|
||||
public int GregorianYear { get; set; }
|
||||
|
||||
//سال شمسی
|
||||
public int PersianYear { get; set; }
|
||||
|
||||
//فعال بودن
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
//آیا هفته جاری است؟
|
||||
public bool IsCurrentWeek { get; set; }
|
||||
|
||||
//تاریخ شروع به شمسی
|
||||
public string StartDatePersian { get; set; } = string.Empty;
|
||||
|
||||
//تاریخ پایان به شمسی
|
||||
public string EndDatePersian { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user