Description
The /getallcourses endpoint currently returns every course from MongoDB in a single response.
As the course collection grows, this can increase response size, database load, and API latency.
Proposed solution
Add server-side query support for:
page
limit
search
category
educator
priceType
sort
Example:
GET /api/user/getallcourses?page=1&limit=12&search=javascript&category=programming&sort=newest
The response should include:
{
"success": true,
"data": [],
"pagination": {
"page": 1,
"limit": 12,
"totalItems": 0,
"totalPages": 0,
"hasNextPage": false,
"hasPreviousPage": false
}
}
Validation requirements
- Default
page to 1.
- Default
limit to a reasonable value such as 12.
- Cap
limit at 100.
- Reject or safely normalize negative and malformed values.
- Escape search input before constructing regular expressions.
- Preserve the existing endpoint path.
- Return an empty array rather than
404 when no courses match.
Acceptance criteria
Suggested files
backend/controllers/userControllers.js
backend/routers/userRoutes.js
backend/utils/pagination.js
backend/tests/course-listing.test.js
Description
The
/getallcoursesendpoint currently returns every course from MongoDB in a single response.As the course collection grows, this can increase response size, database load, and API latency.
Proposed solution
Add server-side query support for:
pagelimitsearchcategoryeducatorpriceTypesortExample:
The response should include:
{ "success": true, "data": [], "pagination": { "page": 1, "limit": 12, "totalItems": 0, "totalPages": 0, "hasNextPage": false, "hasPreviousPage": false } }Validation requirements
pageto1.limitto a reasonable value such as12.limitat100.404when no courses match.Acceptance criteria
Suggested files