apps/recallassess/recallassess-api/src/api/client/course/course.controller.ts
api/client/course
Methods |
|
| Async getPublishedCourseById | ||||||
getPublishedCourseById(id: number)
|
||||||
Decorators :
@HttpCode(HttpStatus.OK)
|
||||||
|
Get a single published course by ID GET /api/client/course/:id
Parameters :
Returns :
Promise<CLCourseDto>
|
| Async getPublishedCourses |
getPublishedCourses()
|
Decorators :
@HttpCode(HttpStatus.OK)
|
|
Get all published courses for client consumption GET /api/client/course
Returns :
Promise<CLCourseDto[]>
|
import { Public } from "@bish-nest/core/auth/decorator/public.decorator";
import { Controller, Get, HttpCode, HttpStatus, NotFoundException, Param, ParseIntPipe } from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { CLCourseService } from "./course.service";
import { CLCourseDto } from "./dto";
@ApiTags("Client - Courses")
@Controller("api/client/course")
export class CLCourseController {
constructor(private courseService: CLCourseService) {}
/**
* Get all published courses for client consumption
* GET /api/client/course
*/
@HttpCode(HttpStatus.OK)
@Public()
@Get()
@ApiOperation({ summary: "Get all published courses" })
@ApiResponse({
status: 200,
description: "Returns array of published courses with enriched data",
type: [CLCourseDto],
})
async getPublishedCourses(): Promise<CLCourseDto[]> {
return this.courseService.getPublishedCourses();
}
/**
* Get a single published course by ID
* GET /api/client/course/:id
*/
@HttpCode(HttpStatus.OK)
@Public()
@Get(":id")
@ApiOperation({ summary: "Get a published course by ID" })
@ApiResponse({
status: 200,
description: "Returns a single published course with enriched data",
type: CLCourseDto,
})
@ApiResponse({
status: 404,
description: "Course not found or not published",
})
async getPublishedCourseById(@Param("id", ParseIntPipe) id: number): Promise<CLCourseDto> {
const course = await this.courseService.getPublishedCourseById(id);
if (!course) {
throw new NotFoundException(`Course with ID ${id} not found or not published`);
}
return course;
}
}