update api chapterlesson

This commit is contained in:
JakkrapartXD 2026-01-22 15:56:56 +07:00
parent 2fc0fb7a76
commit 5c2b5d55aa
11 changed files with 855 additions and 85 deletions

View file

@ -260,7 +260,8 @@ export class ChaptersLessonInstructorController {
token,
course_id: courseId,
chapter_id: chapterId,
lesson_ids: body.lesson_ids,
lesson_id: body.lesson_id,
sort_order: body.sort_order,
});
}

View file

@ -1,59 +0,0 @@
import { Get, Path, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
import { ValidationError } from '../middleware/errorHandler';
import { ChaptersLessonService } from '../services/ChaptersLesson.service';
import {
ListChaptersResponse,
GetLessonResponse,
} from '../types/ChaptersLesson.typs';
const chaptersLessonService = new ChaptersLessonService();
@Route('api/students/courses/{courseId}')
@Tags('ChaptersLessons - Student')
export class ChaptersLessonStudentController {
// ============================================
// Chapter Endpoints (Read-only for students)
// ============================================
/**
* chapters course ( lessons) -
* Get all chapters of a course with lessons - for enrolled students
*/
@Get('chapters')
@Security('jwt', ['student'])
@SuccessResponse('200', 'Chapters retrieved successfully')
@Response('401', 'Unauthorized')
@Response('403', 'Not enrolled in this course')
public async listChapters(@Request() request: any, @Path() courseId: number): Promise<ListChaptersResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) throw new ValidationError('No token provided');
return await chaptersLessonService.listChapters({ token, course_id: courseId });
}
// ============================================
// Lesson Endpoints (Read-only for students)
// ============================================
/**
* lesson attachments quiz -
* Get lesson with attachments and quiz - for enrolled students
* หมายเหตุ: จะดูได้เฉพาะ lesson is_published = true
*/
@Get('chapters/{chapterId}/lessons/{lessonId}')
@Security('jwt', ['student'])
@SuccessResponse('200', 'Lesson retrieved successfully')
@Response('401', 'Unauthorized')
@Response('403', 'Not enrolled or lesson not published')
@Response('404', 'Lesson not found')
public async getLesson(
@Request() request: any,
@Path() courseId: number,
@Path() chapterId: number,
@Path() lessonId: number
): Promise<GetLessonResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) throw new ValidationError('No token provided');
return await chaptersLessonService.getLesson({ token, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
}
}