github-actions[bot]
Deploy Backend from GitHub Actions Commit: 423e3d8f2ea6a4a147ad6e163359781ca419cbf0
9ba737d | import { | |
| Controller, | |
| Get, | |
| Post, | |
| Body, | |
| Param, | |
| Query, | |
| Put, | |
| Delete, | |
| UseInterceptors, | |
| UploadedFile, | |
| BadRequestException, | |
| UseGuards, | |
| Req, | |
| } from "@nestjs/common"; | |
| import { CoursesService } from "./courses.service"; | |
| import { ApiTags, ApiOperation, ApiBearerAuth } from "@nestjs/swagger"; | |
| import { FileInterceptor } from "@nestjs/platform-express"; | |
| import { JwtAuthGuard } from "../auth/jwt-auth.guard"; | |
| import { RolesGuard } from "../auth/roles.guard"; | |
| import { Roles } from "../auth/roles.decorator"; | |
| import { CreateCourseDto } from "./dto/create-course.dto"; | |
| import { UpdateCourseDto } from "./dto/update-course.dto"; | |
| import { UploadDocDto } from "./dto/upload-doc.dto"; | |
| ("Courses & Roadmaps") | |
| () | |
| (JwtAuthGuard, RolesGuard) | |
| () | |
| export class CoursesController { | |
| constructor(private coursesService: CoursesService) {} | |
| // ==================== COURSES ==================== | |
| ("courses") | |
| ("admin") | |
| ({ summary: "Create a new course workspace" }) | |
| async createCourse(() dto: CreateCourseDto, () req: any) { | |
| return this.coursesService.createCourse( | |
| dto.userId || req.user.id, | |
| dto.title, | |
| dto.description, | |
| ); | |
| } | |
| ("courses") | |
| ({ summary: "Retrieve courses list" }) | |
| async getCourses(() req: any, ("userId") userId?: string) { | |
| const resolvedUserId = | |
| req.user.role === "admin" ? userId || req.user.id : req.user.id; | |
| return this.coursesService.getCourses(resolvedUserId); | |
| } | |
| ("courses/:id") | |
| ("admin") | |
| ({ summary: "Retrieve single course details (Admin)" }) | |
| async getCourseById(("id") id: string) { | |
| return this.coursesService.getCourseById(id); | |
| } | |
| ("courses/:id") | |
| ("admin") | |
| ({ summary: "Update course details (Admin)" }) | |
| async updateCourse(("id") id: string, () dto: UpdateCourseDto) { | |
| return this.coursesService.updateCourse(id, dto.title, dto.description); | |
| } | |
| ("courses/:id") | |
| ("admin") | |
| ({ summary: "Delete a course (Admin)" }) | |
| async deleteCourse(("id") id: string) { | |
| return this.coursesService.deleteCourse(id); | |
| } | |
| ("courses/:id/upload") | |
| ("admin") | |
| ({ | |
| summary: | |
| "Upload textbook parsed content to generate roadmap mindmap structure", | |
| }) | |
| async uploadDocument( | |
| ("id") courseId: string, | |
| () dto: UploadDocDto, | |
| ) { | |
| return this.coursesService.processDocumentUpload( | |
| courseId, | |
| dto.fileName, | |
| dto.content, | |
| ); | |
| } | |
| // ==================== BUCKET FILE UPLOADER ==================== | |
| ("files/upload") | |
| ("admin") | |
| (FileInterceptor("file")) | |
| ({ summary: "Upload an arbitrary file to the storage bucket" }) | |
| async uploadFile(() file: any) { | |
| if (!file) { | |
| throw new BadRequestException("No file uploaded"); | |
| } | |
| return this.coursesService.saveUploadedFile( | |
| file.originalname, | |
| file.buffer, | |
| file.mimetype, | |
| ); | |
| } | |
| ("files/lesson-assets/upload") | |
| ("admin") | |
| (FileInterceptor("file")) | |
| ({ summary: "Upload an image asset for lesson flow components" }) | |
| async uploadLessonAsset(() file: any) { | |
| if (!file) { | |
| throw new BadRequestException("No file uploaded"); | |
| } | |
| return this.coursesService.saveLessonAsset( | |
| file.originalname, | |
| file.buffer, | |
| file.mimetype, | |
| ); | |
| } | |
| ("files/lesson-videos/upload") | |
| ("admin") | |
| (FileInterceptor("file")) | |
| ({ summary: "Upload a lesson video file to YouTube" }) | |
| async uploadLessonVideo(() file: any, () body: any) { | |
| if (!file) { | |
| throw new BadRequestException("No file uploaded"); | |
| } | |
| return this.coursesService.uploadLessonVideoToYoutube( | |
| file.originalname, | |
| file.buffer, | |
| file.mimetype, | |
| body?.title, | |
| ); | |
| } | |
| ("files/lesson-videos/url") | |
| ("admin") | |
| ({ summary: "Store a lesson video URL reference in Supabase" }) | |
| async storeLessonVideoUrl(() body: any) { | |
| if (!body?.url) { | |
| throw new BadRequestException("Video URL is required"); | |
| } | |
| return this.coursesService.storeLessonVideoUrl(body.url, body.title); | |
| } | |
| } | |