Issue: Create API to Fetch products Optimally
Description
Develop a new API endpoint to optimally fetch requests, using logic based on the existing fetchAllProducts function. The new function should be named fetchAllProductsOptimal. It must include pagination (5 items per page) and support filtering via query parameters.
Requirements
- Function Name:
fetchAllProductsOptimal
- API Endpoint:
/api/products/get/optimal
- HTTP Method:
GET
Query Parameters
| Parameter |
Type |
Required |
Description |
page |
Number |
No |
Page number for pagination (default: 1) |
products |
String |
No |
Filter by product(s). Accepts comma-separated values. |
Pagination
- Page size is fixed to 5 requests per page.
Response
The API should return a JSON object containing:
data: List of requests matching the filters
pagination:
totalRequests: Total number of matching requests
totalPages: Total pages available
currentPage: Current page number
filtersApplied: An object showing active filters (if any)
Example Successful Response
{
"data": [
{
"id": "REQ123",
"products": ["productA"]
},
...
],
"pagination": {
"products": 17,
"totalPages": 4,
"currentPage": 2
},
"filtersApplied": {
"products": ["productB"]
}
}
Issue: Create API to Fetch products Optimally
Description
Develop a new API endpoint to optimally fetch requests, using logic based on the existing
fetchAllProductsfunction. The new function should be namedfetchAllProductsOptimal. It must include pagination (5 items per page) and support filtering via query parameters.Requirements
fetchAllProductsOptimal/api/products/get/optimalGETQuery Parameters
pageproductsPagination
Response
The API should return a JSON object containing:
data: List of requests matching the filterspagination:totalRequests: Total number of matching requeststotalPages: Total pages availablecurrentPage: Current page numberfiltersApplied: An object showing active filters (if any)Example Successful Response
{ "data": [ { "id": "REQ123", "products": ["productA"] }, ... ], "pagination": { "products": 17, "totalPages": 4, "currentPage": 2 }, "filtersApplied": { "products": ["productB"] } }