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,11 @@
using MediatR;
namespace CMSMicroservice.Application.DiscountShopCQ.Queries.GetCustomerCart;
/// <summary>
/// Query برای دریافت سبد خرید کاربر فعلی
/// </summary>
public class GetCustomerCartQuery : IRequest<GetCustomerCartQueryResponse>
{
// UserId from ICurrentUserService
}
@@ -0,0 +1,68 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace CMSMicroservice.Application.DiscountShopCQ.Queries.GetCustomerCart;
public class GetCustomerCartQueryHandler : IRequestHandler<GetCustomerCartQuery, GetCustomerCartQueryResponse>
{
private readonly IApplicationDbContext _context;
private readonly ICurrentUserService _currentUser;
public GetCustomerCartQueryHandler(IApplicationDbContext context, ICurrentUserService currentUser)
{
_context = context;
_currentUser = currentUser;
}
public async Task<GetCustomerCartQueryResponse> Handle(GetCustomerCartQuery request, CancellationToken cancellationToken)
{
// Extract UserId from JWT token
var userId = long.TryParse(_currentUser.UserId, out var id) ? id : 0;
if (userId == 0)
{
throw new UnauthorizedAccessException("User not authenticated");
}
// Get all cart items for the current user
var cartItems = await _context.UserCarts
.Include(uc => uc.Product)
.Where(uc => uc.UserId == userId)
.ToListAsync(cancellationToken);
var response = new GetCustomerCartQueryResponse
{
TotalItemsCount = cartItems.Sum(c => c.Count),
Message = cartItems.Count > 0 ? "سبد خرید با موفقیت بازیابی شد" : "سبد خرید خالی است"
};
foreach (var item in cartItems)
{
// Use Product.ThumbnailPath directly
var thumbnailPath = item.Product?.ThumbnailPath ?? string.Empty;
var itemPrice = item.Product?.Price ?? 0;
var itemDiscount = item.Product?.Discount ?? 0;
var finalPrice = itemPrice * (100 - itemDiscount) / 100;
var totalItemPrice = finalPrice * item.Count;
response.Items.Add(new CustomerCartItemModel
{
Id = item.Id,
ProductId = item.ProductId,
ProductTitle = item.Product?.Title ?? string.Empty,
ProductShortInformation = item.Product?.ShortInfomation ?? string.Empty, // Typo in DB: ShortInfomation
ProductPrice = itemPrice,
ProductDiscount = itemDiscount,
ProductThumbnailPath = thumbnailPath,
Count = item.Count,
TotalItemPrice = totalItemPrice,
Created = item.Created
});
response.TotalPrice += totalItemPrice;
}
return response;
}
}
@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.DiscountShopCQ.Queries.GetCustomerCart;
public class GetCustomerCartQueryResponse
{
public List<CustomerCartItemModel> Items { get; set; } = new();
public long TotalPrice { get; set; }
public int TotalItemsCount { get; set; }
public string Message { get; set; } = string.Empty;
}
public class CustomerCartItemModel
{
public long Id { get; set; }
public long ProductId { get; set; }
public string ProductTitle { get; set; } = string.Empty;
public string ProductShortInformation { get; set; } = string.Empty;
public long ProductPrice { get; set; }
public int ProductDiscount { get; set; }
public string ProductThumbnailPath { get; set; } = string.Empty;
public int Count { get; set; }
public long TotalItemPrice { get; set; }
public DateTime Created { get; set; }
}