feat: Implement instructor search and improve instructor management with email/username lookup and avatar presigned URLs.

This commit is contained in:
JakkrapartXD 2026-01-29 15:52:10 +07:00
parent 38e7f1bf06
commit f4a12c686b
4 changed files with 228 additions and 25 deletions

View file

@ -1,4 +1,4 @@
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Security, Put, Path, Delete, Request, Example, FormField, UploadedFile } from 'tsoa';
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Security, Put, Path, Delete, Request, Example, FormField, UploadedFile, Query } from 'tsoa';
import { ValidationError } from '../middleware/errorHandler';
import { CoursesInstructorService } from '../services/CoursesInstructor.service';
import {
@ -6,18 +6,16 @@ import {
createCourseResponse,
GetMyCourseResponse,
ListMyCourseResponse,
addinstructorCourse,
addinstructorCourseResponse,
removeinstructorCourse,
removeinstructorCourseResponse,
setprimaryCourseInstructor,
setprimaryCourseInstructorResponse,
UpdateMyCourse,
UpdateMyCourseResponse,
DeleteMyCourseResponse,
submitCourseResponse,
listinstructorCourseResponse,
GetCourseApprovalsResponse
GetCourseApprovalsResponse,
SearchInstructorResponse
} from '../types/CoursesInstructor.types';
import { CreateCourseValidator } from "../validators/CoursesInstructor.validator";
@ -200,20 +198,36 @@ export class CoursesInstructorController {
}
/**
*
* Add a new instructor to the course
*
* Search instructors to add to course
* @param courseId - / Course ID
* @param userId - / User ID to add as instructor
* @param query - (email username) / Search query (email or username)
*/
@Post('add-instructor/{courseId}/{userId}')
@Get('{courseId}/search-instructors')
@Security('jwt', ['instructor'])
@SuccessResponse('200', 'Instructors found')
@Response('401', 'Invalid or expired token')
public async searchInstructors(@Request() request: any, @Path() courseId: number, @Query() query: string): Promise<SearchInstructorResponse> {
const token = request.headers.authorization?.replace('Bearer ', '');
if (!token) throw new ValidationError('No token provided');
return await CoursesInstructorService.searchInstructors({ token, course_id: courseId, query });
}
/**
* ( email username)
* Add a new instructor to the course (using email or username)
* @param courseId - / Course ID
* @param emailOrUsername - email username / Instructor's email or username
*/
@Post('add-instructor/{courseId}/{emailOrUsername}')
@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> {
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() emailOrUsername: string): 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 });
return await CoursesInstructorService.addInstructorToCourse({ token, course_id: courseId, email_or_username: emailOrUsername });
}
/**