MS-245/feat(products): Add optimized product cards search endpoint with dynamic filter counts
Summary
This MR introduces a new optimized endpoint for searching and displaying product cards on the frontend, with dynamic filter counts for better UX.
Motivation
The existing product listing endpoints return heavy DTOs with unnecessary data for card display. This creates performance issues on product listing pages. Additionally, the frontend needs real-time counts for "In Stock" and "On Sale" filters.
Changes
New DTOs
| DTO | Purpose |
|---|---|
ProductCardDTO |
Lightweight DTO with only card-relevant fields |
ProductCardSearchCriteria |
Encapsulates all search/filter parameters |
ProductCardPageResponse |
Paginated response with filter counts |
FilterCountsDTO |
Record containing inStock and onSale counts |
New Endpoint
GET /api/stock/products/cards/search
Query Parameters:
-
categorySlug(optional): Filter by category slug (includes subcategories) -
minPrice/maxPrice(optional): Price range filter -
onSale(optional): Filter products on sale (promoPrice > 0) -
inStock(optional): Filter available products -
keyword(optional): Search in name and description -
page(default: 0): Page number -
size(default: 12): Page size -
sortField(default: createdAt): Sort field -
sortDirection(default: desc): Sort direction
Response includes:
- Paginated list of
ProductCardDTO -
filterCounts.inStockCount: Number of available products -
filterCounts.onSaleCount: Number of products on sale
Performance Optimizations
- Direct DTO projection in JPQL queries (no entity mapping overhead)
- Single query for products + separate count queries for filters
- Efficient category hierarchy handling
Breaking Changes
-
CategoryService.getRelatedProducts()now returnsList<ProductCardDTO>instead ofList<CustomProductRequest> -
ProductService.getProductByCategorySlug()now returnsPage<ProductCardDTO>instead ofPage<CustomProductRequest>
Closes MS-245