Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Delete, | |
| Body, | |
| Param, | |
| UseGuards, | |
| HttpStatus, | |
| HttpCode, | |
| ParseIntPipe, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiBearerAuth, | |
| ApiParam, | |
| ApiBody, | |
| } from '@nestjs/swagger'; | |
| import { CourseSchedulesService } from '../services/course-schedules.service'; | |
| import { CreateScheduleDto } from '../dtos'; | |
| import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../../auth/guards/roles.guard'; | |
| import { Roles } from '../../auth/roles.decorator'; | |
| import { RoleName } from '../../auth/entities/role.entity'; | |
| ('๐ Course Schedules') | |
| ('api/schedules') | |
| export class CourseSchedulesController { | |
| constructor( | |
| private readonly schedulesService: CourseSchedulesService, | |
| ) {} | |
| ('section/:sectionId') | |
| ({ | |
| summary: 'Get schedules by section', | |
| description: `Returns all schedule entries for a specific course section.`, | |
| }) | |
| ({ name: 'sectionId', description: 'Section ID', type: Number, example: 11 }) | |
| ({ status: 200, description: 'List of schedules for the section' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async findBySectionId( | |
| ('sectionId', ParseIntPipe) sectionId: number, | |
| ) { | |
| return this.schedulesService.findBySectionId(sectionId); | |
| } | |
| (':id') | |
| ({ | |
| summary: 'Get schedule by ID', | |
| description: `Returns a specific schedule entry by its ID.`, | |
| }) | |
| ({ name: 'id', description: 'Schedule ID', type: Number, example: 1 }) | |
| ({ status: 200, description: 'Schedule details' }) | |
| ({ status: 404, description: 'Schedule not found' }) | |
| async findById(('id', ParseIntPipe) id: number) { | |
| return this.schedulesService.findById(id); | |
| } | |
| ('section/:sectionId') | |
| (HttpStatus.CREATED) | |
| (JwtAuthGuard, RolesGuard) | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ('JWT-auth') | |
| ({ | |
| summary: 'Create schedule for section', | |
| description: `Creates a new schedule entry (day/time slot) for a course section.`, | |
| }) | |
| ({ name: 'sectionId', description: 'Section ID', type: Number, example: 11 }) | |
| ({ type: CreateScheduleDto }) | |
| ({ status: 201, description: 'Schedule created successfully' }) | |
| ({ status: 400, description: 'Invalid input data' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async create( | |
| ('sectionId', ParseIntPipe) sectionId: number, | |
| () dto: CreateScheduleDto, | |
| ) { | |
| return this.schedulesService.create(sectionId, dto); | |
| } | |
| (':id') | |
| (HttpStatus.NO_CONTENT) | |
| (JwtAuthGuard, RolesGuard) | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ('JWT-auth') | |
| ({ | |
| summary: 'Delete schedule', | |
| description: `Deletes a schedule entry by its ID.`, | |
| }) | |
| ({ name: 'id', description: 'Schedule ID', type: Number, example: 1 }) | |
| ({ status: 204, description: 'Schedule deleted successfully' }) | |
| ({ status: 404, description: 'Schedule not found' }) | |
| async delete(('id', ParseIntPipe) id: number) { | |
| await this.schedulesService.delete(id); | |
| } | |
| } | |