feat: update getCourseById endpoint to return single course response type and improve error handling.
This commit is contained in:
parent
b303c50865
commit
07ab43a785
2 changed files with 10 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Controller, Security, Request, Put, Path, Query } from 'tsoa';
|
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Controller, Security, Request, Put, Path, Query } from 'tsoa';
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
import { ValidationError } from '../middleware/errorHandler';
|
||||||
import { listCourseResponse } from '../types/courses.types';
|
import { listCourseResponse, getCourseResponse } from '../types/courses.types';
|
||||||
import { CoursesService } from '../services/courses.service';
|
import { CoursesService } from '../services/courses.service';
|
||||||
|
|
||||||
@Route('api/courses')
|
@Route('api/courses')
|
||||||
|
|
@ -20,10 +20,15 @@ export class CoursesController {
|
||||||
return await this.coursesService.ListCourses(category_id);
|
return await this.coursesService.ListCourses(category_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ดึงข้อมูลคอร์สตาม ID
|
||||||
|
* Get course by ID
|
||||||
|
* @param id - รหัสคอร์ส / Course ID
|
||||||
|
*/
|
||||||
@Get('{id}')
|
@Get('{id}')
|
||||||
@SuccessResponse('200', 'Course fetched successfully')
|
@SuccessResponse('200', 'Course fetched successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('404', 'Course not found')
|
||||||
public async getCourseById(@Path() id: number): Promise<listCourseResponse> {
|
public async getCourseById(@Path() id: number): Promise<getCourseResponse> {
|
||||||
return await this.coursesService.ListCourses(id);
|
return await this.coursesService.GetCourseById(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export class CoursesService {
|
||||||
if (!course) {
|
if (!course) {
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Course fetched successfully',
|
message: 'no Course fetched successfully',
|
||||||
data: null,
|
data: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,6 @@ export class CoursesService {
|
||||||
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Course fetched successfully',
|
message: 'Course fetched successfully',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue