From b7e4f459422ccba76c090ef61921576b687e900d Mon Sep 17 00:00:00 2001 From: JakkrapartXD Date: Mon, 2 Feb 2026 11:49:23 +0700 Subject: [PATCH] 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. --- .../controllers/announcementsController.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Backend/src/controllers/announcementsController.ts b/Backend/src/controllers/announcementsController.ts index eb1d40be..8c5d855d 100644 --- a/Backend/src/controllers/announcementsController.ts +++ b/Backend/src/controllers/announcementsController.ts @@ -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 { + 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, + }); + } +}