-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from graywenn/feature/question
Feature/question
- Loading branch information
Showing
19 changed files
with
525 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum Resources { | ||
'dashboard' = '1', | ||
'timesheet' = '2', | ||
'attendance' = '3', | ||
'questionBank' = '4', | ||
'codeOnline' = '5', | ||
'createQuestion' = '6', | ||
'updateQuestion' = '7', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Controller, UseGuards, Get, Param, Request } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { NestRes } from '@interfaces/nestbase'; | ||
import { QuestionAnswerService } from '@services/questionAnswer.service'; | ||
|
||
@UseGuards(AuthGuard('jwt')) | ||
@Controller('answer') | ||
export class QuestionAnswerController { | ||
constructor(private readonly questionAnswerService: QuestionAnswerService) {} | ||
|
||
@Get('/last/:questionId/:languageId') | ||
async getUserLastQuestionAnswer( | ||
@Param('questionId') questionId: string, | ||
@Param('languageId') languageId: number, | ||
@Request() req: NestRes, | ||
) { | ||
const data = await this.questionAnswerService.getUserLastQuestionAnswer( | ||
questionId, | ||
req.user.userId, | ||
languageId, | ||
); | ||
|
||
return data?.code || null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
Controller, | ||
UseGuards, | ||
Post, | ||
Body, | ||
Get, | ||
Param, | ||
Put, | ||
Request, | ||
HttpException, | ||
HttpStatus, | ||
} from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { | ||
ICreateQuestionBankBody, | ||
IUpdateQuestionBankBody, | ||
} from '@models/questionBank.model'; | ||
import { QuestionBankService } from '@services/questionBank.service'; | ||
import { NestRes } from '@interfaces/nestbase'; | ||
import { QuestionAnswerService } from '@services/questionAnswer.service'; | ||
import { Resources } from '@constants/resources'; | ||
|
||
@UseGuards(AuthGuard('jwt')) | ||
@Controller('question') | ||
export class QuestionBankController { | ||
constructor( | ||
private readonly questionAnswerService: QuestionAnswerService, | ||
private readonly questionBankService: QuestionBankService, | ||
) {} | ||
|
||
@Get('/list') | ||
async getQuestionList(@Request() req: NestRes) { | ||
const authorized = req.user.resources.includes(Resources.updateQuestion); | ||
return await this.questionBankService.getQuestionList( | ||
req.user.userId, | ||
authorized, | ||
); | ||
} | ||
|
||
@Get('/:questionId') | ||
async getQuestion(@Param('questionId') questionId: string) { | ||
return await this.questionBankService.getQuestion(questionId); | ||
} | ||
|
||
verifyQuestion(question: ICreateQuestionBankBody) { | ||
if (!question.name) { | ||
throw new HttpException('题目名称不能为空', HttpStatus.BAD_REQUEST); | ||
} | ||
try { | ||
JSON.parse(JSON.stringify(question.cases)); | ||
JSON.parse(JSON.stringify(question.entryCodes)); | ||
} catch (error) { | ||
throw new HttpException(JSON.stringify(error), HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
|
||
@Post() | ||
async createQuestion( | ||
@Body() body: ICreateQuestionBankBody, | ||
@Request() req: NestRes, | ||
) { | ||
this.verifyQuestion(body); | ||
body.userId = req.user.userId; | ||
body.userName = req.user.username; | ||
return await this.questionBankService.createQuestion(body); | ||
} | ||
|
||
@Put() | ||
async updateQuestion( | ||
@Body() body: IUpdateQuestionBankBody, | ||
@Request() req: NestRes, | ||
) { | ||
this.verifyQuestion(body); | ||
body.userId = req.user.userId; | ||
body.userName = req.user.username; | ||
return await this.questionBankService.updateQuestion(body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Column, Entity } from 'typeorm'; | ||
|
||
@Entity({ name: 'question_answer' }) | ||
export class QuestionAnswer { | ||
@Column({ primary: true, generated: 'uuid' }) | ||
id: string; | ||
@Column('varchar', { length: 50, nullable: true }) | ||
questionId: string; | ||
@Column('int2', { nullable: true }) | ||
languageId: number; | ||
@Column('varchar', { length: 50, nullable: true }) | ||
userId: string; | ||
@Column('text', { nullable: true }) | ||
code: string; | ||
@Column('text', { nullable: true }) | ||
result: string; | ||
@Column('boolean', { nullable: true }) | ||
isPassed: boolean; | ||
@Column('double precision', { nullable: true }) | ||
elapsedTime: number; | ||
@Column('timestamp') | ||
createTime: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Column, Entity } from 'typeorm'; | ||
|
||
@Entity({ name: 'question_contributor' }) | ||
export class QuestionContributor { | ||
@Column({ primary: true, generated: 'uuid' }) | ||
id: string; | ||
@Column('varchar', { length: 50, nullable: true }) | ||
questionId: string; | ||
@Column('varchar', { length: 50, nullable: true }) | ||
userId: string; | ||
@Column('varchar', { length: 50, nullable: true }) | ||
userName: string; | ||
@Column('timestamp') | ||
createTime: string; | ||
} |
Oops, something went wrong.