feat: update getCourseById endpoint to return single course response type and improve error handling.

This commit is contained in:
JakkrapartXD 2026-01-28 17:08:44 +07:00
parent b303c50865
commit 07ab43a785
2 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,6 @@
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Controller, Security, Request, Put, Path, Query } from 'tsoa';
import { ValidationError } from '../middleware/errorHandler';
import { listCourseResponse } from '../types/courses.types';
import { listCourseResponse, getCourseResponse } from '../types/courses.types';
import { CoursesService } from '../services/courses.service';
@Route('api/courses')
@ -20,10 +20,15 @@ export class CoursesController {
return await this.coursesService.ListCourses(category_id);
}
/**
* ID
* Get course by ID
* @param id - / Course ID
*/
@Get('{id}')
@SuccessResponse('200', 'Course fetched successfully')
@Response('401', 'Invalid or expired token')
public async getCourseById(@Path() id: number): Promise<listCourseResponse> {
return await this.coursesService.ListCourses(id);
@Response('404', 'Course not found')
public async getCourseById(@Path() id: number): Promise<getCourseResponse> {
return await this.coursesService.GetCourseById(id);
}
}

View file

@ -61,7 +61,7 @@ export class CoursesService {
if (!course) {
return {
code: 200,
message: 'Course fetched successfully',
message: 'no Course fetched successfully',
data: null,
};
}
@ -75,7 +75,6 @@ export class CoursesService {
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
}
}
return {
code: 200,
message: 'Course fetched successfully',