feat: add pagination and random sorting to course listing endpoint with configurable page size and Fisher-Yates shuffle algorithm
This commit is contained in:
parent
217c9c29b8
commit
3f93dc8ab5
3 changed files with 57 additions and 6 deletions
|
|
@ -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 });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue