Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate copy course to new api #2316

Merged
merged 9 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/services/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CoursesService {
}

async createCourseCopy(data: Partial<Course>, id: number) {
const result = await axios.post<CourseResponse>(`/api/course/${id}/copy`, data);
const result = await axios.post<CourseResponse>(`/api/v2/courses/${id}/copy`, data);
return result.data.data;
}

Expand Down
19 changes: 18 additions & 1 deletion nestjs/src/courses/courses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import { CourseGuard } from '../auth/course.guard';
import { CourseAccessService } from './course-access.service';
import { CoursesService } from './courses.service';
import { CourseDto, LeaveCourseRequestDto, UpdateCourseDto } from './dto';
import { CopyCourseDto } from './dto/copy-course.dto';
import { CourseScheduleService } from './course-schedule/course-schedule.service';

@Controller('courses')
@ApiTags('courses')
@ApiTags('courses schedule')
export class CoursesController {
constructor(
private courseService: CoursesService,
private courseAccessService: CourseAccessService,
private courseScheduleService: CourseScheduleService,
) {}

@Get('/')
Expand Down Expand Up @@ -88,4 +91,18 @@ export class CoursesController {
await this.courseAccessService.rejoinAsStudent(courseId, studentId);
}
}

@Post('/:courseId/copy')
@ApiOkResponse({})
@ApiOperation({ operationId: 'copyCourse' })
@ApiBody({ type: CopyCourseDto, required: true })
@UseGuards(DefaultGuard, RoleGuard)
@RequiredRoles([CourseRole.Manager, Role.Admin])
public async copyscheduleCourse(@Req() req: CurrentRequest, @Param('courseId') courseId: number) {
const created = await this.courseService.create(req.body);
if (created.id) {
await this.courseScheduleService.copyFromTo(courseId, created.id);
}
return await this.courseService.getById(created.id);
}
}
6 changes: 6 additions & 0 deletions nestjs/src/courses/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Course } from '@entities/course';
import { InjectRepository } from '@nestjs/typeorm';
import { FindOptionsWhere, In, Repository } from 'typeorm';
import { UpdateCourseDto } from './dto';
import { CreateCourseDto } from './dto/create-course.dto';

@Injectable()
export class CoursesService {
Expand All @@ -24,6 +25,11 @@ export class CoursesService {
return this.repository.findOneByOrFail({ id });
}

public async create(course: CreateCourseDto) {
const created = await this.repository.save(course);
return this.repository.findOneByOrFail({ id: created.id });
}

public async getByIds(ids: number[], filter?: FindOptionsWhere<Course>) {
return this.repository.find({
where: {
Expand Down
51 changes: 51 additions & 0 deletions nestjs/src/courses/dto/copy-course.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApiProperty } from '@nestjs/swagger';

export class CopyCourseDto {
@ApiProperty()
name: string;

@ApiProperty()
startDate: string;

@ApiProperty()
endDate: string;

@ApiProperty()
fullName: string;

@ApiProperty()
alias: string;

@ApiProperty({ required: false })
registrationEndDate: string | null;

@ApiProperty({ required: false })
completed: boolean;

@ApiProperty({ required: false })
planned: boolean;

@ApiProperty({ required: false })
inviteOnly: boolean;

@ApiProperty()
description: string;

@ApiProperty({ required: false })
disciplineId: number;

@ApiProperty({ required: false })
discordServerId: number;

@ApiProperty({ required: false })
usePrivateRepositories: boolean;

@ApiProperty({ required: false })
certificateIssuer: string;

@ApiProperty({ required: false })
personalMentoring: boolean;

@ApiProperty({ required: false })
logo: string;
}
51 changes: 51 additions & 0 deletions nestjs/src/courses/dto/create-course.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateCourseDto {
@ApiProperty()
name: string;

@ApiProperty()
startDate: string;

@ApiProperty()
endDate: string;

@ApiProperty()
fullName: string;

@ApiProperty()
alias: string;

@ApiProperty({ required: false })
registrationEndDate: string;

@ApiProperty({ required: false })
completed: boolean;

@ApiProperty({ required: false })
planned: boolean;

@ApiProperty({ required: false })
inviteOnly: boolean;

@ApiProperty()
description: string;

@ApiProperty({ required: false })
disciplineId: number;

@ApiProperty({ required: false })
discordServerId: number;

@ApiProperty({ required: false })
usePrivateRepositories: boolean;

@ApiProperty({ required: false })
certificateIssuer: string;

@ApiProperty({ required: false })
personalMentoring: boolean;

@ApiProperty({ required: false })
logo: string;
}
9 changes: 9 additions & 0 deletions nestjs/src/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@
"tags": ["courses"]
}
},
"/courses/{courseId}/copy": {
"post": {
"operationId": "copyCourse",
"summary": "",
"parameters": [{ "name": "courseId", "required": true, "in": "path", "schema": { "type": "number" } }],
"responses": { "201": { "description": "" } },
"tags": ["courses"]
}
},
"/students/{studentId}": {
"get": {
"operationId": "getStudent",
Expand Down