feat: Implement instructor search and improve instructor management with email/username lookup and avatar presigned URLs.
This commit is contained in:
parent
38e7f1bf06
commit
f4a12c686b
4 changed files with 228 additions and 25 deletions
|
|
@ -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 });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue