Skip to content

feat: Add pagination to product list endpoint and collection page#129

Open
Kavinayaboopathi wants to merge 1 commit intoNsanjayboruds:mainfrom
Kavinayaboopathi:feature/pagination
Open

feat: Add pagination to product list endpoint and collection page#129
Kavinayaboopathi wants to merge 1 commit intoNsanjayboruds:mainfrom
Kavinayaboopathi:feature/pagination

Conversation

@Kavinayaboopathi
Copy link
Copy Markdown

This PR introduces backend pagination for the product list endpoint and integrates minimal frontend support for fetching and displaying paginated products on the Collections page. This ensures better performance and faster frontend load times as the product count grows.

Changes Made
Backend

productController.js
: Updated

listProducts
to accept page, limit, and category query parameters.
Implemeted .skip() and .limit() database queries to fetch limited batches of products.
Returns paginated data (total, page, pages) alongside the products array.
Maintained backward compatibility: If the endpoint is hit without pagination parameters, it continues to return the default flat array of all products.
Frontend

ShopContext.jsx
: Added

getPaginatedProducts
helper function to construct queries and fetch the paginated endpoint.

Collections.jsx
:
Refactored the initial page load to fetch the first page from the backend.
Wired the "Load More Products" button to dynamically fetch sequential pages and append them to the UI list instead of triggering local dummy states.
Features a built-in fallback: If complex filters are selected on the UI, the frontend seamlessly transitions back into client-side array-based filtering.
Acceptance Criteria Supported
Backend responds to page, limit and category query params.
Valid pagination metadata (total, page, pages) is returned.
Zero-parameter API call remains backward compatible.

Frontend
Collections
page successfully consumes paginated states.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant