feat: add student endpoint for listing course announcements
Add new AnnouncementsStudentController with GET endpoint for students to retrieve course announcements with pagination support. Endpoint requires JWT authentication and validates course enrollment.
This commit is contained in:
parent
18b8f4501f
commit
b7e4f45942
1 changed files with 33 additions and 0 deletions
|
|
@ -193,3 +193,36 @@ export class AnnouncementsController {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Route('api/student/courses/{courseId}/announcements')
|
||||
@Tags('CoursesStudent')
|
||||
export class AnnouncementsStudentController {
|
||||
|
||||
/**
|
||||
* ดึงรายการประกาศของคอร์ส (สำหรับนักเรียน)
|
||||
* List announcements for a course (for students)
|
||||
* @param courseId - รหัสคอร์ส / Course ID
|
||||
* @param page - หน้าที่ต้องการ / Page number
|
||||
* @param limit - จำนวนต่อหน้า / Items per page
|
||||
*/
|
||||
@Get()
|
||||
@Security('jwt')
|
||||
@SuccessResponse('200', 'Announcements retrieved successfully')
|
||||
@Response('401', 'Unauthorized')
|
||||
@Response('403', 'Forbidden - Not enrolled in this course')
|
||||
public async listAnnouncements(
|
||||
@Request() request: any,
|
||||
@Path() courseId: number,
|
||||
@Query() page?: number,
|
||||
@Query() limit?: number
|
||||
): Promise<ListAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.listAnnouncement({
|
||||
token,
|
||||
course_id: courseId,
|
||||
page,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue