File size: 3,292 Bytes
3b492d9
 
 
 
 
 
 
e6b22aa
3b492d9
 
 
 
89ee94c
 
 
 
e6b22aa
89ee94c
 
 
3b492d9
 
e6b22aa
 
 
 
3b492d9
89ee94c
3b492d9
 
 
 
 
 
 
89ee94c
 
 
 
 
 
 
3b492d9
 
 
 
 
 
 
89ee94c
 
 
 
 
 
 
3b492d9
 
 
 
 
 
e6b22aa
 
 
89ee94c
 
 
 
 
 
 
 
 
3b492d9
 
 
 
 
 
 
 
 
e6b22aa
 
 
89ee94c
 
 
 
 
 
 
3b492d9
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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';

@ApiTags('🕐 Course Schedules')
@Controller('api/schedules')
export class CourseSchedulesController {
  constructor(
    private readonly schedulesService: CourseSchedulesService,
  ) {}

  @Get('section/:sectionId')
  @ApiOperation({
    summary: 'Get schedules by section',
    description: `Returns all schedule entries for a specific course section.`,
  })
  @ApiParam({ name: 'sectionId', description: 'Section ID', type: Number, example: 11 })
  @ApiResponse({ status: 200, description: 'List of schedules for the section' })
  @ApiResponse({ status: 404, description: 'Section not found' })
  async findBySectionId(
    @Param('sectionId', ParseIntPipe) sectionId: number,
  ) {
    return this.schedulesService.findBySectionId(sectionId);
  }

  @Get(':id')
  @ApiOperation({
    summary: 'Get schedule by ID',
    description: `Returns a specific schedule entry by its ID.`,
  })
  @ApiParam({ name: 'id', description: 'Schedule ID', type: Number, example: 1 })
  @ApiResponse({ status: 200, description: 'Schedule details' })
  @ApiResponse({ status: 404, description: 'Schedule not found' })
  async findById(@Param('id', ParseIntPipe) id: number) {
    return this.schedulesService.findById(id);
  }

  @Post('section/:sectionId')
  @HttpCode(HttpStatus.CREATED)
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles(RoleName.ADMIN, RoleName.IT_ADMIN)
  @ApiBearerAuth('JWT-auth')
  @ApiOperation({
    summary: 'Create schedule for section',
    description: `Creates a new schedule entry (day/time slot) for a course section.`,
  })
  @ApiParam({ name: 'sectionId', description: 'Section ID', type: Number, example: 11 })
  @ApiBody({ type: CreateScheduleDto })
  @ApiResponse({ status: 201, description: 'Schedule created successfully' })
  @ApiResponse({ status: 400, description: 'Invalid input data' })
  @ApiResponse({ status: 404, description: 'Section not found' })
  async create(
    @Param('sectionId', ParseIntPipe) sectionId: number,
    @Body() dto: CreateScheduleDto,
  ) {
    return this.schedulesService.create(sectionId, dto);
  }

  @Delete(':id')
  @HttpCode(HttpStatus.NO_CONTENT)
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles(RoleName.ADMIN, RoleName.IT_ADMIN)
  @ApiBearerAuth('JWT-auth')
  @ApiOperation({
    summary: 'Delete schedule',
    description: `Deletes a schedule entry by its ID.`,
  })
  @ApiParam({ name: 'id', description: 'Schedule ID', type: Number, example: 1 })
  @ApiResponse({ status: 204, description: 'Schedule deleted successfully' })
  @ApiResponse({ status: 404, description: 'Schedule not found' })
  async delete(@Param('id', ParseIntPipe) id: number) {
    await this.schedulesService.delete(id);
  }
}