|
1 | | -import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; |
| 1 | +import { |
| 2 | + Body, |
| 3 | + Controller, |
| 4 | + Delete, |
| 5 | + Get, |
| 6 | + HttpStatus, |
| 7 | + Param, |
| 8 | + Patch, |
| 9 | + Post, |
| 10 | + Req, |
| 11 | + UseGuards, |
| 12 | +} from '@nestjs/common'; |
2 | 13 | import { UserService } from './user.service'; |
3 | 14 | import { AuthenticatedGuard } from 'src/auth/authenticated.guard'; |
4 | 15 | import { Request } from 'express'; |
5 | | -import { UserSettings } from './types'; |
| 16 | +import { UserSettings, AddCourseDto } from './types'; |
6 | 17 |
|
7 | 18 | interface AuthenticatedRequest extends Request { |
8 | 19 | user: { |
@@ -49,4 +60,102 @@ export class UserController { |
49 | 60 | await this.userService.setSettings(req.user.id, settings); |
50 | 61 | return; |
51 | 62 | } |
| 63 | + |
| 64 | + @Get('courses/:timetableId') |
| 65 | + @UseGuards(AuthenticatedGuard) |
| 66 | + async getCourseIds( |
| 67 | + @Req() req: AuthenticatedRequest, |
| 68 | + @Param('timetableId') timetableId: string, |
| 69 | + ) { |
| 70 | + return await this.userService.getCourseIds(req.user.id, timetableId); |
| 71 | + } |
| 72 | + |
| 73 | + @Post('course/:timetableId/:courseId') |
| 74 | + @UseGuards(AuthenticatedGuard) |
| 75 | + async addCourse( |
| 76 | + @Req() req: AuthenticatedRequest, |
| 77 | + @Param('timetableId') timetableId: string, |
| 78 | + @Param('courseId') courseId: string, |
| 79 | + @Body() addCourseDto: AddCourseDto, |
| 80 | + ) { |
| 81 | + await this.userService.addCourse( |
| 82 | + req.user.id, |
| 83 | + timetableId, |
| 84 | + courseId, |
| 85 | + addCourseDto, |
| 86 | + ); |
| 87 | + return HttpStatus.CREATED; |
| 88 | + } |
| 89 | + |
| 90 | + @Delete('course/:timetableId/:courseId') |
| 91 | + @UseGuards(AuthenticatedGuard) |
| 92 | + async removeCourse( |
| 93 | + @Req() req: AuthenticatedRequest, |
| 94 | + @Param('timetableId') timetableId: string, |
| 95 | + @Param('courseId') courseId: string, |
| 96 | + ) { |
| 97 | + await this.userService.removeCourse(req.user.id, timetableId, courseId); |
| 98 | + } |
| 99 | + |
| 100 | + @Patch('course/:timetableId/:courseId/colour') |
| 101 | + @UseGuards(AuthenticatedGuard) |
| 102 | + async setCourseColour( |
| 103 | + @Req() req: AuthenticatedRequest, |
| 104 | + @Param('timetableId') timetableId: string, |
| 105 | + @Param('courseId') courseId: string, |
| 106 | + @Body('colour') colour: string, |
| 107 | + ) { |
| 108 | + await this.userService.setCourseColour( |
| 109 | + req.user.id, |
| 110 | + timetableId, |
| 111 | + courseId, |
| 112 | + colour, |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + @Get('classes/:timetableId/:courseId') |
| 117 | + @UseGuards(AuthenticatedGuard) |
| 118 | + async getSelectedClassIds( |
| 119 | + @Req() req: AuthenticatedRequest, |
| 120 | + @Param('timetableId') timetableId: string, |
| 121 | + @Param('courseId') courseId: string, |
| 122 | + ) { |
| 123 | + return await this.userService.getSelectedClassIds( |
| 124 | + req.user.id, |
| 125 | + timetableId, |
| 126 | + courseId, |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + @Patch('class/:timetableId/:courseId') |
| 131 | + @UseGuards(AuthenticatedGuard) |
| 132 | + async updateSelectedClass( |
| 133 | + @Req() req: AuthenticatedRequest, |
| 134 | + @Param('timetableId') timetableId: string, |
| 135 | + @Param('courseId') courseId: string, |
| 136 | + @Body('classId') classId: string, |
| 137 | + ) { |
| 138 | + await this.userService.updateSelectedClass( |
| 139 | + req.user.id, |
| 140 | + timetableId, |
| 141 | + courseId, |
| 142 | + classId, |
| 143 | + ); |
| 144 | + } |
| 145 | + |
| 146 | + @Delete('class/:timetableId/:courseId/:classId') |
| 147 | + @UseGuards(AuthenticatedGuard) |
| 148 | + async removeSelectedClass( |
| 149 | + @Req() req: AuthenticatedRequest, |
| 150 | + @Param('timetableId') timetableId: string, |
| 151 | + @Param('courseId') courseId: string, |
| 152 | + @Param('classId') classId: string, |
| 153 | + ) { |
| 154 | + await this.userService.removeSelectedClass( |
| 155 | + req.user.id, |
| 156 | + timetableId, |
| 157 | + courseId, |
| 158 | + classId, |
| 159 | + ); |
| 160 | + } |
52 | 161 | } |
0 commit comments