Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Patch, | |
| Delete, | |
| Body, | |
| Param, | |
| Query, | |
| UseGuards, | |
| HttpStatus, | |
| HttpCode, | |
| ParseIntPipe, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiBearerAuth, | |
| ApiParam, | |
| ApiQuery, | |
| ApiBody, | |
| } from '@nestjs/swagger'; | |
| import { CourseSectionsService } from '../services/course-sections.service'; | |
| import { CreateSectionDto, UpdateSectionDto } 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 Sections') | |
| ('api/sections') | |
| export class CourseSectionsController { | |
| constructor( | |
| private readonly sectionsService: CourseSectionsService, | |
| ) {} | |
| ('course/:courseId') | |
| ({ | |
| summary: 'Get sections by course', | |
| description: ` | |
| ## Get Course Sections | |
| Retrieves all sections for a specific course, optionally filtered by semester. | |
| ### Access Control | |
| - **Authentication Required**: No (Public endpoint) | |
| - **Roles Required**: None | |
| ### Filtering | |
| Use \`semesterId\` to filter sections for a specific semester. | |
| `, | |
| }) | |
| ({ name: 'courseId', description: 'Course ID', type: Number }) | |
| ({ name: 'semesterId', required: false, type: Number }) | |
| ({ status: 200, description: 'List of course sections' }) | |
| ({ status: 404, description: 'Course not found' }) | |
| async findByCourseId( | |
| ('courseId', ParseIntPipe) courseId: number, | |
| ('semesterId', new ParseIntPipe({ optional: true })) | |
| semesterId?: number, | |
| ) { | |
| return this.sectionsService.findByCourseId(courseId, semesterId); | |
| } | |
| (':id') | |
| ({ | |
| summary: 'Get section by ID', | |
| description: ` | |
| ## Get Section Details | |
| Retrieves detailed information about a specific course section. | |
| ### Access Control | |
| - **Authentication Required**: No (Public endpoint) | |
| - **Roles Required**: None | |
| ### Response Includes | |
| - Section information (number, capacity) | |
| - Instructor details | |
| - Schedule information | |
| - Current enrollment count | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Section ID', type: Number }) | |
| ({ status: 200, description: 'Section details' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async findById(('id', ParseIntPipe) id: number) { | |
| return this.sectionsService.findById(id); | |
| } | |
| () | |
| (HttpStatus.CREATED) | |
| (JwtAuthGuard, RolesGuard) | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ('JWT-auth') | |
| ({ | |
| summary: 'Create new section', | |
| description: ` | |
| ## Create Course Section | |
| Creates a new section for a course. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token recommended) | |
| - **Roles Required**: ADMIN, IT_ADMIN, INSTRUCTOR | |
| ### Required Fields | |
| - Course ID | |
| - Semester ID | |
| - Section number | |
| - Capacity | |
| - Instructor ID | |
| `, | |
| }) | |
| ({ type: CreateSectionDto }) | |
| ({ status: 201, description: 'Section created successfully' }) | |
| ({ status: 400, description: 'Invalid input data' }) | |
| ({ status: 409, description: 'Section number already exists for this course/semester' }) | |
| async create(() dto: CreateSectionDto) { | |
| return this.sectionsService.create(dto); | |
| } | |
| (':id') | |
| (JwtAuthGuard, RolesGuard) | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ('JWT-auth') | |
| ({ | |
| summary: 'Update section', | |
| description: ` | |
| ## Update Course Section | |
| Updates an existing course section. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token recommended) | |
| - **Roles Required**: ADMIN, IT_ADMIN, INSTRUCTOR (section owner) | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Section ID', type: Number }) | |
| ({ type: UpdateSectionDto }) | |
| ({ status: 200, description: 'Section updated successfully' }) | |
| ({ status: 400, description: 'Invalid input data' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async update( | |
| ('id', ParseIntPipe) id: number, | |
| () dto: UpdateSectionDto, | |
| ) { | |
| return this.sectionsService.update(id, dto); | |
| } | |
| (':id/enrollment') | |
| (JwtAuthGuard, RolesGuard) | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ('JWT-auth') | |
| ({ | |
| summary: 'Update section enrollment count', | |
| description: ` | |
| ## Update Section Enrollment | |
| Updates the current enrollment count for a section. | |
| ### Access Control | |
| - **Authentication Required**: ✅ Yes (Bearer Token recommended) | |
| - **Roles Required**: ADMIN, IT_ADMIN, INSTRUCTOR | |
| ### Notes | |
| This is typically called automatically by the enrollment system. | |
| `, | |
| }) | |
| ({ name: 'id', description: 'Section ID', type: Number }) | |
| ({ | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| currentEnrollment: { type: 'number', example: 25 }, | |
| }, | |
| }, | |
| }) | |
| ({ status: 200, description: 'Enrollment count updated' }) | |
| ({ status: 404, description: 'Section not found' }) | |
| async updateEnrollment( | |
| ('id', ParseIntPipe) id: number, | |
| ('currentEnrollment') currentEnrollment: number, | |
| ) { | |
| await this.sectionsService.updateEnrollment(id, currentEnrollment); | |
| return this.sectionsService.findById(id); | |
| } | |
| } | |