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:
+8
@@ -0,0 +1,8 @@
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransaction;
|
||||
|
||||
public class GetCustomerTransactionQuery : IRequest<GetCustomerTransactionResponseDto>
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
public string Authority { get; set; }
|
||||
public long UserId { get; set; }
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
using CMSMicroservice.Application.Common.Exceptions;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Domain.Entities;
|
||||
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransaction;
|
||||
|
||||
public class GetCustomerTransactionQueryHandler : IRequestHandler<GetCustomerTransactionQuery, GetCustomerTransactionResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public GetCustomerTransactionQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
ICurrentUserService currentUser)
|
||||
{
|
||||
_context = context;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerTransactionResponseDto> Handle(GetCustomerTransactionQuery 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");
|
||||
|
||||
// Transaction entity doesn't have UserId, so we need to find it through UserOrders
|
||||
var transaction = await _context.Transactions
|
||||
.AsNoTracking()
|
||||
.Where(x => request.Id.HasValue ? x.Id == request.Id.Value : true)
|
||||
.Include(x => x.UserOrders)
|
||||
.Where(x => x.UserOrders.Any(o => o.UserId == userId))
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (transaction == null)
|
||||
throw new NotFoundException(nameof(Transaction), request.Id ?? 0);
|
||||
|
||||
return new GetCustomerTransactionResponseDto
|
||||
{
|
||||
Id = transaction.Id,
|
||||
Amount = transaction.Amount,
|
||||
Description = transaction.Description ?? "",
|
||||
PaymentStatus = transaction.PaymentStatus,
|
||||
PaymentDate = transaction.PaymentDate,
|
||||
RefId = transaction.RefId ?? "",
|
||||
Type = transaction.Type
|
||||
};
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransaction;
|
||||
|
||||
public class GetCustomerTransactionResponseDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long Amount { get; set; }
|
||||
public string Description { get; set; }
|
||||
public PaymentStatus PaymentStatus { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string RefId { get; set; }
|
||||
public TransactionType Type { get; set; }
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransactionsByFilter;
|
||||
|
||||
public class GetCustomerTransactionsByFilterQuery : IRequest<GetCustomerTransactionsByFilterResponseDto>
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
public PaginationState PaginationState { get; set; }
|
||||
public string SortBy { get; set; }
|
||||
public long? IdFilter { get; set; }
|
||||
public long? AmountFilter { get; set; }
|
||||
public string DescriptionFilter { get; set; }
|
||||
public bool? PaymentStatusFilter { get; set; }
|
||||
public string RefIdFilter { get; set; }
|
||||
public int? TypeFilter { get; set; }
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
using CMSMicroservice.Application.Common.Extensions;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransactionsByFilter;
|
||||
|
||||
public class GetCustomerTransactionsByFilterQueryHandler : IRequestHandler<GetCustomerTransactionsByFilterQuery, GetCustomerTransactionsByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public GetCustomerTransactionsByFilterQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
ICurrentUserService currentUser)
|
||||
{
|
||||
_context = context;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task<GetCustomerTransactionsByFilterResponseDto> Handle(GetCustomerTransactionsByFilterQuery 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");
|
||||
|
||||
// Transaction doesn't have UserId, find through UserOrders
|
||||
var query = _context.Transactions
|
||||
.AsNoTracking()
|
||||
.Include(x => x.UserOrders)
|
||||
.Where(x => x.UserOrders.Any(o => o.UserId == userId))
|
||||
.AsQueryable();
|
||||
|
||||
// Apply filters
|
||||
if (request.IdFilter.HasValue)
|
||||
query = query.Where(x => x.Id == request.IdFilter.Value);
|
||||
|
||||
if (request.AmountFilter.HasValue)
|
||||
query = query.Where(x => x.Amount == request.AmountFilter.Value);
|
||||
|
||||
if (!string.IsNullOrEmpty(request.DescriptionFilter))
|
||||
query = query.Where(x => x.Description.Contains(request.DescriptionFilter));
|
||||
|
||||
if (request.PaymentStatusFilter.HasValue)
|
||||
{
|
||||
var status = request.PaymentStatusFilter.Value
|
||||
? Domain.Enums.PaymentStatus.Success
|
||||
: Domain.Enums.PaymentStatus.Reject;
|
||||
query = query.Where(x => x.PaymentStatus == status);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.RefIdFilter))
|
||||
query = query.Where(x => x.RefId == request.RefIdFilter);
|
||||
|
||||
if (request.TypeFilter.HasValue)
|
||||
query = query.Where(x => (int)x.Type == request.TypeFilter.Value);
|
||||
|
||||
// Apply sorting
|
||||
if (!string.IsNullOrEmpty(request.SortBy))
|
||||
query = query.ApplyOrder(request.SortBy);
|
||||
else
|
||||
query = query.OrderByDescending(x => x.Created);
|
||||
|
||||
// Get metadata
|
||||
var metaData = await query.GetMetaData(request.PaginationState, cancellationToken);
|
||||
|
||||
// Get paginated results
|
||||
var transactions = await query
|
||||
.PaginatedListAsync(request.PaginationState)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var models = transactions.Select(t => new CustomerTransactionModel
|
||||
{
|
||||
Id = t.Id,
|
||||
Amount = t.Amount,
|
||||
Description = t.Description ?? "",
|
||||
PaymentStatus = t.PaymentStatus,
|
||||
PaymentDate = t.PaymentDate,
|
||||
RefId = t.RefId ?? "",
|
||||
Type = t.Type
|
||||
}).ToList();
|
||||
|
||||
return new GetCustomerTransactionsByFilterResponseDto
|
||||
{
|
||||
MetaData = metaData,
|
||||
Models = models
|
||||
};
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
|
||||
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetCustomerTransactionsByFilter;
|
||||
|
||||
public class GetCustomerTransactionsByFilterResponseDto
|
||||
{
|
||||
public MetaData MetaData { get; set; }
|
||||
public List<CustomerTransactionModel> Models { get; set; } = new();
|
||||
}
|
||||
|
||||
public class CustomerTransactionModel
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long Amount { get; set; }
|
||||
public string Description { get; set; }
|
||||
public PaymentStatus PaymentStatus { get; set; }
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
public string RefId { get; set; }
|
||||
public TransactionType Type { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user