feat: Introduce API endpoints and refactor service methods for adding, removing, listing, and setting primary course instructors.

This commit is contained in:
JakkrapartXD 2026-01-16 17:52:36 +07:00
parent 2e536ad193
commit b5ca6b2e0f
3 changed files with 66 additions and 8 deletions

View file

@ -15,7 +15,8 @@ import {
UpdateMyCourse,
UpdateMyCourseResponse,
DeleteMyCourseResponse,
submitCourseResponse
submitCourseResponse,
listinstructorCourseResponse
} from '../types/CoursesInstructor.types';
import { CreateCourseValidator } from "../validators/CoursesInstructor.validator";
@ -105,5 +106,55 @@ export class CoursesInstructorController {
return await CoursesInstructorService.sendCourseForReview({ token, course_id: courseId });
}
@Get('listinstructor/{courseId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Instructors retrieved successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Instructors not found')
public async listInstructorCourses(@Request() request: any, @Path() courseId: number): Promise<listinstructorCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
}
@Post('add-instructor/{courseId}/{userId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Instructor added successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Instructor not found')
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<addinstructorCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.addInstructorToCourse({ token, course_id: courseId, user_id: userId });
}
@Post('remove-instructor/{courseId}/{userId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Instructor removed successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Instructor not found')
public async removeInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<removeinstructorCourseResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.removeInstructorFromCourse({ token, course_id: courseId, user_id: userId });
}
@Post('set-primary-instructor/{courseId}/{userId}')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Primary instructor set successfully')
@Response('401', 'Invalid or expired token')
@Response('404', 'Primary instructor not found')
public async setPrimaryInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<setprimaryCourseInstructorResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) {
throw new ValidationError('No token provided');
}
return await CoursesInstructorService.setPrimaryInstructor({ token, course_id: courseId, user_id: userId });
}
}