Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Param, | |
| UseGuards, | |
| Request, | |
| ParseIntPipe, | |
| Body, | |
| } from '@nestjs/common'; | |
| import { CoursesService } from './courses.service'; | |
| import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; | |
| ('api/courses') | |
| export class CoursesController { | |
| constructor(private readonly coursesService: CoursesService) {} | |
| () | |
| async findAll() { | |
| const data = await this.coursesService.findAll(); | |
| return { success: true, data }; | |
| } | |
| (JwtAuthGuard) | |
| ('my') | |
| async findMyCourses(() req) { | |
| const data = await this.coursesService.getUserCourses(req.user.userId); | |
| return { success: true, data }; | |
| } | |
| (JwtAuthGuard) | |
| ('my-stars') | |
| async findMyStars(() req) { | |
| const data = await this.coursesService.getUserStars(req.user.userId); | |
| return { success: true, data }; | |
| } | |
| (':id') | |
| async findOne(('id', ParseIntPipe) id: number) { | |
| const data = await this.coursesService.findOne(id); | |
| return { success: true, data }; | |
| } | |
| (':id/view') | |
| async incrementViewCount(('id', ParseIntPipe) id: number) { | |
| await this.coursesService.incrementViewCount(id); | |
| return { success: true }; | |
| } | |
| (':id/like') | |
| async toggleLike(('id', ParseIntPipe) id: number) { | |
| await this.coursesService.toggleLike(id); | |
| return { success: true }; | |
| } | |
| (JwtAuthGuard) | |
| (':id/star') | |
| async toggleStar(('id', ParseIntPipe) id: number, () req) { | |
| await this.coursesService.toggleStar(id, req.user.userId); | |
| return { success: true }; | |
| } | |
| (JwtAuthGuard) | |
| (':id/access') | |
| async getAccess(('id', ParseIntPipe) id: number, () req) { | |
| const data = await this.coursesService.getCourseAccess(req.user.userId, id); | |
| return { success: true, data }; | |
| } | |
| (':id/comments') | |
| async getComments(('id', ParseIntPipe) id: number) { | |
| const data = await this.coursesService.getComments(id); | |
| return { success: true, data }; | |
| } | |
| (JwtAuthGuard) | |
| (':id/comments') | |
| async addComment( | |
| ('id', ParseIntPipe) id: number, | |
| () body: { content: string; parentId?: number; replyToCommentId?: number }, | |
| () req, | |
| ) { | |
| const data = await this.coursesService.addComment( | |
| id, | |
| req.user.userId, | |
| body.content, | |
| body.parentId, | |
| body.replyToCommentId, | |
| ); | |
| return { success: true, data }; | |
| } | |
| } | |