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,13 @@
using CMSMicroservice.Application.Common.Models;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrders;
public class GetCustomerOrdersQuery : IRequest<GetCustomerOrdersResponseDto>
{
public long UserId { get; set; }
public PaginationState PaginationState { get; set; }
public int? PaymentStatusFilter { get; set; }
public int? DeliveryStatusFilter { get; set; }
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
}
@@ -0,0 +1,103 @@
using CMSMicroservice.Application.Common.Extensions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Application.Common.Models;
using Mapster;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrders;
public class GetCustomerOrdersQueryHandler : IRequestHandler<GetCustomerOrdersQuery, GetCustomerOrdersResponseDto>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetCustomerOrdersQueryHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<GetCustomerOrdersResponseDto> Handle(GetCustomerOrdersQuery request, CancellationToken cancellationToken)
{
// Resolve UserId from JWT if not specified
var userId = request.UserId == 0
? (long.TryParse(_currentUser.UserId, out var currentUserId) ? currentUserId : 0)
: request.UserId;
if (userId == 0)
throw new UnauthorizedAccessException("User ID not found");
var query = _context.UserOrders
.AsNoTracking()
.Where(x => x.UserId == userId)
.Include(x => x.Package)
.Include(x => x.Transaction)
.Include(x => x.UserAddress)
.Include(x => x.User)
.Include(x => x.FactorDetails)
.ThenInclude(f => f.Product)
.Include(x => x.OrderVAT)
.AsQueryable();
// Apply filters
if (request.PaymentStatusFilter.HasValue)
query = query.Where(x => (int)x.PaymentStatus == request.PaymentStatusFilter.Value);
if (request.DeliveryStatusFilter.HasValue)
query = query.Where(x => (int)x.DeliveryStatus == request.DeliveryStatusFilter.Value);
if (request.FromDate.HasValue)
query = query.Where(x => x.Created >= request.FromDate.Value);
if (request.ToDate.HasValue)
query = query.Where(x => x.Created <= request.ToDate.Value);
// Order by most recent first
query = query.OrderByDescending(x => x.Created);
// Get metadata
var metaData = await query.GetMetaData(request.PaginationState, cancellationToken);
// Get paginated results
var orders = await query
.PaginatedListAsync(request.PaginationState)
.ToListAsync(cancellationToken);
var models = orders.Select(order => new CustomerOrderModel
{
Id = order.Id,
Amount = order.Amount,
PackageId = order.PackageId,
TransactionId = order.TransactionId,
PaymentStatus = order.PaymentStatus,
PaymentDate = order.PaymentDate,
UserId = order.UserId,
UserAddressId = order.UserAddressId,
PaymentMethod = order.PaymentMethod,
UserAddressText = order.UserAddress?.Address ?? "",
DeliveryStatus = order.DeliveryStatus,
TrackingCode = order.TrackingCode ?? "",
DeliveryDescription = order.DeliveryDescription ?? "",
UserFullName = $"{order.User?.FirstName ?? ""} {order.User?.LastName ?? ""}".Trim(),
UserNationalCode = order.User?.NationalCode ?? "",
VatAmount = order.OrderVAT?.VATAmount ?? 0,
VatPercentage = order.OrderVAT != null ? (double)order.OrderVAT.VATRate * 100 : 0,
FactorDetails = order.FactorDetails?.Select(fd => new FactorDetailModel
{
ProductId = fd.ProductId,
ProductTitle = fd.Product?.Title ?? "",
ProductThumbnailPath = fd.Product?.ThumbnailPath ?? "",
UnitPrice = fd.UnitPrice,
Count = fd.Count,
UnitDiscountPrice = fd.UnitDiscountPrice
}).ToList() ?? new List<FactorDetailModel>()
}).ToList();
return new GetCustomerOrdersResponseDto
{
MetaData = metaData,
Models = models
};
}
}
@@ -0,0 +1,42 @@
using CMSMicroservice.Application.Common.Models;
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrders;
public class GetCustomerOrdersResponseDto
{
public MetaData MetaData { get; set; }
public List<CustomerOrderModel> Models { get; set; } = new();
}
public class CustomerOrderModel
{
public long Id { get; set; }
public long Amount { get; set; }
public long? PackageId { get; set; }
public long? TransactionId { get; set; }
public PaymentStatus PaymentStatus { get; set; }
public DateTime? PaymentDate { get; set; }
public long UserId { get; set; }
public long UserAddressId { get; set; }
public PaymentMethod? PaymentMethod { get; set; }
public string UserAddressText { get; set; }
public List<FactorDetailModel> FactorDetails { get; set; } = new();
public DeliveryStatus DeliveryStatus { get; set; }
public string TrackingCode { get; set; }
public string DeliveryDescription { get; set; }
public string UserFullName { get; set; }
public string UserNationalCode { get; set; }
public long VatAmount { get; set; }
public double VatPercentage { get; set; }
}
public class FactorDetailModel
{
public long ProductId { get; set; }
public string ProductTitle { get; set; }
public string ProductThumbnailPath { get; set; }
public long? UnitPrice { get; set; }
public int? Count { get; set; }
public long? UnitDiscountPrice { get; set; }
}