110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Post,
|
|
Get,
|
|
Param,
|
|
Body,
|
|
Query,
|
|
HttpCode,
|
|
HttpStatus,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { EnrollmentService } from './enrollment.service';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { User } from '@coursecraft/database';
|
|
import { SubmitQuizDto } from './dto/submit-quiz.dto';
|
|
import { CreateReviewDto } from './dto/create-review.dto';
|
|
import { SubmitHomeworkDto } from './dto/submit-homework.dto';
|
|
|
|
@ApiTags('enrollment')
|
|
@Controller('enrollment')
|
|
@ApiBearerAuth()
|
|
export class EnrollmentController {
|
|
constructor(private enrollmentService: EnrollmentService) {}
|
|
|
|
@Post(':courseId/enroll')
|
|
@HttpCode(HttpStatus.CREATED)
|
|
@ApiOperation({ summary: 'Enroll in a course' })
|
|
async enroll(@Param('courseId') courseId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.enrollmentService.enroll(user.id, courseId);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get my enrolled courses' })
|
|
async myEnrollments(@CurrentUser() user: User): Promise<any> {
|
|
return this.enrollmentService.getUserEnrollments(user.id);
|
|
}
|
|
|
|
@Get(':courseId/progress')
|
|
@ApiOperation({ summary: 'Get my progress for a course' })
|
|
async getProgress(@Param('courseId') courseId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.enrollmentService.getProgress(user.id, courseId);
|
|
}
|
|
|
|
@Post(':courseId/lessons/:lessonId/complete')
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({ summary: 'Mark a lesson as completed' })
|
|
async completeLesson(
|
|
@Param('courseId') courseId: string,
|
|
@Param('lessonId') lessonId: string,
|
|
@CurrentUser() user: User,
|
|
): Promise<any> {
|
|
return this.enrollmentService.completeLesson(user.id, courseId, lessonId);
|
|
}
|
|
|
|
@Post(':courseId/lessons/:lessonId/quiz')
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({ summary: 'Submit quiz score' })
|
|
async submitQuiz(
|
|
@Param('courseId') courseId: string,
|
|
@Param('lessonId') lessonId: string,
|
|
@Body() dto: SubmitQuizDto,
|
|
@CurrentUser() user: User,
|
|
): Promise<any> {
|
|
return this.enrollmentService.submitQuiz(user.id, courseId, lessonId, dto.answers);
|
|
}
|
|
|
|
@Get(':courseId/lessons/:lessonId/homework')
|
|
@ApiOperation({ summary: 'Get (or lazy-create) homework for lesson' })
|
|
async getHomework(
|
|
@Param('courseId') courseId: string,
|
|
@Param('lessonId') lessonId: string,
|
|
@CurrentUser() user: User,
|
|
): Promise<any> {
|
|
return this.enrollmentService.getHomework(user.id, courseId, lessonId);
|
|
}
|
|
|
|
@Post(':courseId/lessons/:lessonId/homework')
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({ summary: 'Submit written homework for lesson' })
|
|
async submitHomework(
|
|
@Param('courseId') courseId: string,
|
|
@Param('lessonId') lessonId: string,
|
|
@Body() dto: SubmitHomeworkDto,
|
|
@CurrentUser() user: User,
|
|
): Promise<any> {
|
|
return this.enrollmentService.submitHomework(user.id, courseId, lessonId, dto.content);
|
|
}
|
|
|
|
@Post(':courseId/review')
|
|
@HttpCode(HttpStatus.CREATED)
|
|
@ApiOperation({ summary: 'Leave a review' })
|
|
async createReview(
|
|
@Param('courseId') courseId: string,
|
|
@Body() body: CreateReviewDto,
|
|
@CurrentUser() user: User,
|
|
): Promise<any> {
|
|
return this.enrollmentService.createReview(user.id, courseId, body.rating, body.title, body.content);
|
|
}
|
|
|
|
@Get(':courseId/reviews')
|
|
@ApiOperation({ summary: 'Get course reviews' })
|
|
async getReviews(
|
|
@Param('courseId') courseId: string,
|
|
@Query('page') page?: number,
|
|
@Query('limit') limit?: number,
|
|
): Promise<any> {
|
|
return this.enrollmentService.getCourseReviews(courseId, page, limit);
|
|
}
|
|
}
|