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:
+11
@@ -0,0 +1,11 @@
|
||||
using MediatR;
|
||||
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetCustomerAddresses;
|
||||
|
||||
/// <summary>
|
||||
/// Query برای دریافت لیست آدرسهای کاربر فعلی
|
||||
/// </summary>
|
||||
public class GetCustomerAddressesQuery : IRequest<GetCustomerAddressesQueryResponse>
|
||||
{
|
||||
// UserId from ICurrentUserService
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetCustomerAddresses;
|
||||
|
||||
public class GetCustomerAddressesQueryHandler : IRequestHandler<GetCustomerAddressesQuery, GetCustomerAddressesQueryResponse>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public GetCustomerAddressesQueryHandler(IApplicationDbContext context, ICurrentUserService currentUser)
|
||||
{
|
||||
_context = context;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerAddressesQueryResponse> Handle(GetCustomerAddressesQuery 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 addresses for the current user
|
||||
var addresses = await _context.UserAddresses
|
||||
.Where(ua => ua.UserId == userId && !ua.IsDeleted)
|
||||
.OrderByDescending(ua => ua.IsDefault)
|
||||
.ThenByDescending(ua => ua.Created)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var response = new GetCustomerAddressesQueryResponse();
|
||||
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
response.Addresses.Add(new CustomerAddressModel
|
||||
{
|
||||
Id = addr.Id,
|
||||
Title = addr.Title,
|
||||
Address = addr.Address,
|
||||
PostalCode = addr.PostalCode,
|
||||
IsDefault = addr.IsDefault,
|
||||
CityId = addr.CityId,
|
||||
CityName = string.Empty, // Will be populated by FrontOffice from City service
|
||||
ProvinceName = string.Empty // Will be populated by FrontOffice from City service
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
namespace CMSMicroservice.Application.UserAddressCQ.Queries.GetCustomerAddresses;
|
||||
|
||||
public class GetCustomerAddressesQueryResponse
|
||||
{
|
||||
public List<CustomerAddressModel> Addresses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class CustomerAddressModel
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Address { get; set; } = string.Empty;
|
||||
public string PostalCode { get; set; } = string.Empty;
|
||||
public bool IsDefault { get; set; }
|
||||
public long CityId { get; set; }
|
||||
public string CityName { get; set; } = string.Empty;
|
||||
public string ProvinceName { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user