feat(club-membership): enhance club membership history queries and responses
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 17m54s
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 17m54s
- Added filtering capabilities to GetClubMembershipHistoryQuery, allowing optional filters for UserId, ClubMembershipId, Action, and date range. - Updated GetClubMembershipHistoryQueryHandler to utilize the new filter structure. - Enhanced GetAllClubMembershipsQueryHandler to include LastPackage details in the response. - Introduced new properties in GetAllClubMembershipsResponseModel for PackageId and PackageName. - Updated Protobuf definitions to reflect changes in club membership history queries and responses. - Refactored mapping configurations to accommodate new DTOs and filters.
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
using CMSMicroservice.Domain.Enums;
|
||||
|
||||
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
|
||||
|
||||
public record GetAllUserPackagePurchaseByFilterQuery : IRequest<GetAllUserPackagePurchaseByFilterResponseDto>
|
||||
{
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
public string? SortBy { get; init; }
|
||||
public GetAllUserPackagePurchaseByFilterFilter? Filter { get; init; }
|
||||
}
|
||||
|
||||
public class GetAllUserPackagePurchaseByFilterFilter
|
||||
{
|
||||
public long? UserId { get; set; }
|
||||
public long? PackageId { get; set; }
|
||||
public PackagePurchaseMethod? PurchaseMethod { get; set; }
|
||||
public DateTime? PurchasedFrom { get; set; }
|
||||
public DateTime? PurchasedTo { get; set; }
|
||||
public long? MinAmount { get; set; }
|
||||
public long? MaxAmount { get; set; }
|
||||
}
|
||||
|
||||
public class GetAllUserPackagePurchaseByFilterResponseDto
|
||||
{
|
||||
public MetaData MetaData { get; set; }
|
||||
public List<GetAllUserPackagePurchaseByFilterResponseModel>? Models { get; set; }
|
||||
}
|
||||
|
||||
public class GetAllUserPackagePurchaseByFilterResponseModel
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public long UserId { get; set; }
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string UserMobile { get; set; } = string.Empty;
|
||||
public long PackageId { get; set; }
|
||||
public string PackageName { get; set; } = string.Empty;
|
||||
public PackagePurchaseMethod PurchaseMethod { get; set; }
|
||||
public DateTime PurchasedAt { get; set; }
|
||||
public long Amount { get; set; }
|
||||
public long? OrderId { get; set; }
|
||||
public long? TransactionId { get; set; }
|
||||
public DateTimeOffset Created { get; set; }
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
|
||||
|
||||
public class GetAllUserPackagePurchaseByFilterQueryHandler
|
||||
: IRequestHandler<GetAllUserPackagePurchaseByFilterQuery, GetAllUserPackagePurchaseByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllUserPackagePurchaseByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllUserPackagePurchaseByFilterResponseDto> Handle(
|
||||
GetAllUserPackagePurchaseByFilterQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.UserPackagePurchases
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Package)
|
||||
.AsNoTracking()
|
||||
.ApplyUserPackagePurchaseFilter(request.Filter)
|
||||
.ApplyOrder(sortBy: request.SortBy ?? "-PurchasedAt");
|
||||
|
||||
return new GetAllUserPackagePurchaseByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query
|
||||
.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.Select(x => new GetAllUserPackagePurchaseByFilterResponseModel
|
||||
{
|
||||
Id = x.Id,
|
||||
UserId = x.UserId,
|
||||
UserName = x.User != null ? $"{x.User.FirstName} {x.User.LastName}" : string.Empty,
|
||||
UserMobile = x.User != null ? x.User.Mobile : string.Empty,
|
||||
PackageId = x.PackageId,
|
||||
PackageName = x.Package != null ? x.Package.Title : string.Empty,
|
||||
PurchaseMethod = x.PurchaseMethod,
|
||||
PurchasedAt = x.PurchasedAt,
|
||||
Amount = x.Amount,
|
||||
OrderId = x.OrderId,
|
||||
TransactionId = x.TransactionId,
|
||||
Created = x.Created
|
||||
})
|
||||
.ToListAsync(cancellationToken)
|
||||
};
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using CMSMicroservice.Domain.Entities;
|
||||
|
||||
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
|
||||
|
||||
public static class UserPackagePurchaseFilterExtensions
|
||||
{
|
||||
public static IQueryable<UserPackagePurchase> ApplyUserPackagePurchaseFilter(
|
||||
this IQueryable<UserPackagePurchase> query,
|
||||
GetAllUserPackagePurchaseByFilterFilter? filter)
|
||||
{
|
||||
if (filter == null) return query;
|
||||
|
||||
if (filter.UserId.HasValue)
|
||||
query = query.Where(x => x.UserId == filter.UserId.Value);
|
||||
|
||||
if (filter.PackageId.HasValue)
|
||||
query = query.Where(x => x.PackageId == filter.PackageId.Value);
|
||||
|
||||
if (filter.PurchaseMethod.HasValue)
|
||||
query = query.Where(x => x.PurchaseMethod == filter.PurchaseMethod.Value);
|
||||
|
||||
if (filter.PurchasedFrom.HasValue)
|
||||
query = query.Where(x => x.PurchasedAt >= filter.PurchasedFrom.Value);
|
||||
|
||||
if (filter.PurchasedTo.HasValue)
|
||||
query = query.Where(x => x.PurchasedAt <= filter.PurchasedTo.Value);
|
||||
|
||||
if (filter.MinAmount.HasValue)
|
||||
query = query.Where(x => x.Amount >= filter.MinAmount.Value);
|
||||
|
||||
if (filter.MaxAmount.HasValue)
|
||||
query = query.Where(x => x.Amount <= filter.MaxAmount.Value);
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetUserPackagePurchaseSummary;
|
||||
|
||||
public record GetUserPackagePurchaseSummaryQuery : IRequest<GetUserPackagePurchaseSummaryResponseDto>
|
||||
{
|
||||
public GetAllUserPackagePurchaseByFilter.GetAllUserPackagePurchaseByFilterFilter? Filter { get; init; }
|
||||
}
|
||||
|
||||
public class GetUserPackagePurchaseSummaryResponseDto
|
||||
{
|
||||
public long TotalCount { get; set; }
|
||||
public long TotalAmount { get; set; }
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
|
||||
|
||||
namespace CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetUserPackagePurchaseSummary;
|
||||
|
||||
public class GetUserPackagePurchaseSummaryQueryHandler
|
||||
: IRequestHandler<GetUserPackagePurchaseSummaryQuery, GetUserPackagePurchaseSummaryResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetUserPackagePurchaseSummaryQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetUserPackagePurchaseSummaryResponseDto> Handle(
|
||||
GetUserPackagePurchaseSummaryQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.UserPackagePurchases
|
||||
.AsNoTracking()
|
||||
.ApplyUserPackagePurchaseFilter(request.Filter);
|
||||
|
||||
var totalCount = await query.LongCountAsync(cancellationToken);
|
||||
var totalAmount = totalCount > 0 ? await query.SumAsync(x => x.Amount, cancellationToken) : 0;
|
||||
|
||||
return new GetUserPackagePurchaseSummaryResponseDto
|
||||
{
|
||||
TotalCount = totalCount,
|
||||
TotalAmount = totalAmount
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user