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,7 @@
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrder;
public class GetCustomerOrderQuery : IRequest<GetCustomerOrderResponseDto>
{
public long OrderId { get; set; }
public long UserId { get; set; }
}
@@ -0,0 +1,75 @@
using CMSMicroservice.Application.Common.Exceptions;
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrder;
public class GetCustomerOrderQueryHandler : IRequestHandler<GetCustomerOrderQuery, GetCustomerOrderResponseDto>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetCustomerOrderQueryHandler(
IApplicationDbContext context,
ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<GetCustomerOrderResponseDto> Handle(GetCustomerOrderQuery 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 order = await _context.UserOrders
.AsNoTracking()
.Where(x => x.Id == request.OrderId && 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)
.FirstOrDefaultAsync(cancellationToken);
if (order == null)
throw new NotFoundException(nameof(UserOrder), request.OrderId);
return new GetCustomerOrderResponseDto
{
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 FactorDetailDto
{
ProductId = fd.ProductId,
ProductTitle = fd.Product?.Title ?? "",
ProductThumbnailPath = fd.Product?.ThumbnailPath ?? "",
UnitPrice = fd.UnitPrice,
Count = fd.Count,
UnitDiscountPrice = fd.UnitDiscountPrice
}).ToList() ?? new List<FactorDetailDto>()
};
}
}
@@ -0,0 +1,35 @@
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrder;
public class GetCustomerOrderResponseDto
{
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<FactorDetailDto> 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 FactorDetailDto
{
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; }
}