feat: add pagination and random sorting to course listing endpoint with configurable page size and Fisher-Yates shuffle algorithm

This commit is contained in:
JakkrapartXD 2026-02-06 17:41:03 +07:00
parent 217c9c29b8
commit 3f93dc8ab5
3 changed files with 57 additions and 6 deletions

View file

@ -12,12 +12,20 @@ export class CoursesController {
* ( filter category_id )
* Get all courses (can filter by category_id)
* @param category_id - / Category ID (optional)
* @param page - / Page number (default: 1)
* @param limit - / Items per page (default: 10)
* @param random - / Randomize courses order (default: false)
*/
@Get()
@SuccessResponse('200', 'Courses fetched successfully')
@Response('401', 'Invalid or expired token')
public async listCourses(@Query() category_id?: number): Promise<listCourseResponse> {
return await this.coursesService.ListCourses(category_id);
public async listCourses(
@Query() category_id?: number,
@Query() page?: number,
@Query() limit?: number,
@Query() random?: boolean
): Promise<listCourseResponse> {
return await this.coursesService.ListCourses({ category_id, page, limit, random });
}
/**