feat: extend discount product gRPC API with sort_by and sale_count
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 7m11s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 7m11s
- Add sort_by (StringValue) to GetDiscountProductsRequest proto to enable dynamic sorting - Add sale_count (int32) to DiscountProductDto proto for top-seller exposure - Update GetDiscountProductsQuery with SortBy property - Update GetDiscountProductsQueryHandler to use ApplyOrder(SortBy) with fallback to Created desc; project SaleCount in SELECT - Add SortBy and SaleCount Mapster mappings in DiscountProductProfile - Bump CMSMicroservice.Protobuf version to 0.0.196 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+1
@@ -11,6 +11,7 @@ public class GetDiscountProductsQuery : IRequest<GetDiscountProductsResponseDto>
|
||||
public bool? IsActive { get; set; }
|
||||
public int? MinPrice { get; set; }
|
||||
public int? MaxPrice { get; set; }
|
||||
public string? SortBy { get; set; }
|
||||
}
|
||||
|
||||
public class GetDiscountProductsResponseDto
|
||||
|
||||
+7
-3
@@ -1,3 +1,4 @@
|
||||
using CMSMicroservice.Application.Common.Extensions;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Application.Common.Models;
|
||||
using MediatR;
|
||||
@@ -51,13 +52,16 @@ public class GetDiscountProductsQueryHandler : IRequestHandler<GetDiscountProduc
|
||||
query = query.Where(p => p.Price <= request.MaxPrice.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.SortBy))
|
||||
query = query.ApplyOrder(request.SortBy);
|
||||
else
|
||||
query = query.OrderByDescending(p => p.Created);
|
||||
|
||||
var totalCount = await query.CountAsync(cancellationToken);
|
||||
|
||||
// Apply pagination
|
||||
var pagination = request.PaginationQuery ?? new PaginationState { PageNumber = 1, PageSize = 10 };
|
||||
|
||||
|
||||
var products = await query
|
||||
.OrderByDescending(p => p.Created)
|
||||
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
|
||||
.Take(pagination.PageSize)
|
||||
.Select(p => new DiscountProductDto
|
||||
|
||||
Reference in New Issue
Block a user