feat: Implement customer profile and referral queries

- Add GetCustomerProfileResponseDto for retrieving customer profile information.
- Create GetCustomerReferralsQuery and GetCustomerReferralsQueryHandler to fetch customer referrals with pagination and filtering options.
- Introduce GetCustomerReferralsResponseDto to structure the response for customer referrals.
- Implement GetCustomerSettingsQuery and GetCustomerSettingsQueryHandler to retrieve user settings.
- Add GetCustomerOrder and GetCustomerOrderQueryHandler for fetching specific customer orders.
- Create GetCustomerOrderHistoryQuery and GetCustomerOrderHistoryQueryHandler to retrieve order history with filtering options.
- Implement GetCustomerOrdersQuery and GetCustomerOrdersQueryHandler for fetching multiple customer orders with filters.
- Add GetCustomerWalletChangeLogQuery and GetCustomerWalletChangeLogQueryHandler for retrieving wallet change logs.
- Implement GetCustomerWithdrawalSettingsQuery and GetCustomerWithdrawalSettingsQueryHandler for fetching withdrawal settings.
- Create GetCustomerWithdrawalsQuery and GetCustomerWithdrawalsQueryHandler to retrieve customer withdrawal requests.
This commit is contained in:
masoodafar-web
2026-02-05 23:01:50 +03:30
parent b41342dcad
commit b2d676b555
96 changed files with 4822 additions and 589 deletions
@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
public class GetCustomerWalletChangeLogQuery : IRequest<List<GetCustomerWalletChangeLogResponseDto>>
{
/// <summary>
/// فیلتر بر اساس شناسه ارجاع (اختیاری)
/// </summary>
public long? ReferenceId { get; set; }
/// <summary>
/// فیلتر بر اساس نوع تغییر - افزایشی یا کاهشی (اختیاری)
/// </summary>
public bool? IsIncrease { get; set; }
}
@@ -0,0 +1,61 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
public class GetCustomerWalletChangeLogQueryHandler : IRequestHandler<GetCustomerWalletChangeLogQuery, List<GetCustomerWalletChangeLogResponseDto>>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetCustomerWalletChangeLogQueryHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<List<GetCustomerWalletChangeLogResponseDto>> Handle(
GetCustomerWalletChangeLogQuery request,
CancellationToken cancellationToken)
{
// Get current user's ID from JWT
if (!long.TryParse(_currentUser.UserId, out var currentUserId))
{
throw new UnauthorizedAccessException("User ID not found in token");
}
// Get user's wallet
var userWallet = await _context.UserWallets
.AsNoTracking()
.Where(x => x.UserId == currentUserId)
.FirstOrDefaultAsync(cancellationToken);
if (userWallet == null)
{
throw new NotFoundException(nameof(UserWallet), currentUserId);
}
// Build query for wallet change logs
var query = _context.UserWalletChangeLogs
.AsNoTracking()
.Where(x => x.WalletId == userWallet.Id);
// Apply optional filters
if (request.ReferenceId.HasValue)
{
query = query.Where(x => x.RefrenceId == request.ReferenceId.Value);
}
if (request.IsIncrease.HasValue)
{
query = query.Where(x => x.IsIncrease == request.IsIncrease.Value);
}
// Order by newest first
var result = await query
.OrderByDescending(x => x.Created)
.ProjectToType<GetCustomerWalletChangeLogResponseDto>()
.ToListAsync(cancellationToken);
return result;
}
}
@@ -0,0 +1,39 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletChangeLog;
public class GetCustomerWalletChangeLogResponseDto
{
/// <summary>
/// موجودی جاری
/// </summary>
public long CurrentBalance { get; set; }
/// <summary>
/// مقدار تغییر
/// </summary>
public long ChangeValue { get; set; }
/// <summary>
/// موجودی جاری شبکه
/// </summary>
public long CurrentNetworkBalance { get; set; }
/// <summary>
/// مقدار تغییر شبکه
/// </summary>
public long ChangeNerworkValue { get; set; }
/// <summary>
/// افزایشی است؟
/// </summary>
public bool IsIncrease { get; set; }
/// <summary>
/// شناسه ارجاع
/// </summary>
public long? RefrenceId { get; set; }
/// <summary>
/// تاریخ ایجاد
/// </summary>
public DateTime Created { get; set; }
}
@@ -0,0 +1,6 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawalSettings;
public class GetCustomerWithdrawalSettingsQuery : IRequest<GetCustomerWithdrawalSettingsResponseDto>
{
// No parameters needed - returns system-wide settings
}
@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawalSettings;
public class GetCustomerWithdrawalSettingsQueryHandler : IRequestHandler<GetCustomerWithdrawalSettingsQuery, GetCustomerWithdrawalSettingsResponseDto>
{
// TODO: In future, read from SystemConfiguration table
private const long MIN_WITHDRAWAL_AMOUNT = 50000; // 50,000 Rials
public Task<GetCustomerWithdrawalSettingsResponseDto> Handle(
GetCustomerWithdrawalSettingsQuery request,
CancellationToken cancellationToken)
{
var response = new GetCustomerWithdrawalSettingsResponseDto
{
MinWithdrawalAmount = MIN_WITHDRAWAL_AMOUNT
};
return Task.FromResult(response);
}
}
@@ -0,0 +1,9 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawalSettings;
public class GetCustomerWithdrawalSettingsResponseDto
{
/// <summary>
/// حداقل مبلغ برداشت (ریال)
/// </summary>
public long MinWithdrawalAmount { get; set; }
}
@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawals;
public class GetCustomerWithdrawalsQuery : IRequest<List<GetCustomerWithdrawalsResponseDto>>
{
/// <summary>
/// فیلتر بر اساس وضعیت (اختیاری)
/// 0: Pending, 1: Paid, 2: WithdrawRequested, 3: Withdrawn, 4: PaymentFailed, 5: Cancelled
/// </summary>
public int? Status { get; set; }
}
@@ -0,0 +1,56 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawals;
public class GetCustomerWithdrawalsQueryHandler : IRequestHandler<GetCustomerWithdrawalsQuery, List<GetCustomerWithdrawalsResponseDto>>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetCustomerWithdrawalsQueryHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<List<GetCustomerWithdrawalsResponseDto>> Handle(
GetCustomerWithdrawalsQuery request,
CancellationToken cancellationToken)
{
// Get current user's ID from JWT
if (!long.TryParse(_currentUser.UserId, out var currentUserId))
{
throw new UnauthorizedAccessException("User ID not found in token");
}
// Build query for user's commission payouts (withdrawals)
var query = _context.UserCommissionPayouts
.AsNoTracking()
.Include(x => x.WeekDefinition)
.Where(x => x.UserId == currentUserId);
// Apply status filter if provided
if (request.Status.HasValue)
{
query = query.Where(x => (int)x.Status == request.Status.Value);
}
// Order by newest first and map to DTO
var result = await query
.OrderByDescending(x => x.Created)
.Select(x => new GetCustomerWithdrawalsResponseDto
{
Id = x.Id,
WeekDefinitionId = x.WeekDefinitionId,
WeekDisplayName = x.WeekDefinition.DisplayName ?? "",
TotalAmount = x.TotalAmount,
Status = (int)x.Status,
WithdrawalMethod = x.WithdrawalMethod.HasValue ? (int)x.WithdrawalMethod.Value : null,
IbanNumber = x.IbanNumber ?? "",
Created = x.Created
})
.ToListAsync(cancellationToken);
return result;
}
}
@@ -0,0 +1,44 @@
namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWithdrawals;
public class GetCustomerWithdrawalsResponseDto
{
/// <summary>
/// شناسه
/// </summary>
public long Id { get; set; }
/// <summary>
/// شناسه تعریف هفته
/// </summary>
public long WeekDefinitionId { get; set; }
/// <summary>
/// نام نمایشی هفته
/// </summary>
public string WeekDisplayName { get; set; }
/// <summary>
/// مبلغ کل
/// </summary>
public long TotalAmount { get; set; }
/// <summary>
/// وضعیت
/// </summary>
public int Status { get; set; }
/// <summary>
/// روش برداشت
/// </summary>
public int? WithdrawalMethod { get; set; }
/// <summary>
/// شماره شبا
/// </summary>
public string IbanNumber { get; set; }
/// <summary>
/// تاریخ ایجاد
/// </summary>
public DateTime Created { get; set; }
}
@@ -2,21 +2,28 @@ namespace CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
public class GetUserWalletQueryHandler : IRequestHandler<GetUserWalletQuery, GetUserWalletResponseDto>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetUserWalletQueryHandler(IApplicationDbContext context)
public GetUserWalletQueryHandler(IApplicationDbContext context, ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<GetUserWalletResponseDto> Handle(GetUserWalletQuery request,
CancellationToken cancellationToken)
{
// If Id is 0 or not provided, get the current authenticated user's ID
var userId = request.Id == 0
? (long.TryParse(_currentUser.UserId, out var currentUserId) ? currentUserId : 0)
: request.Id;
var response = await _context.UserWallets
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Where(x => x.UserId == userId) // Changed from x.Id to x.UserId
.ProjectToType<GetUserWalletResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserWallet), request.Id);
return response ?? throw new NotFoundException(nameof(UserWallet), userId);
}
}
@@ -9,5 +9,6 @@ public class GetUserWalletResponseDto
public long Balance { get; set; }
//موجودی شبکه
public long NetworkBalance { get; set; }
//موجودی تخفیف
public long DiscountBalance { get; set; }
}