diff --git a/src/codingtest/codingtest.controller.ts b/src/codingtest/codingtest.controller.ts index 34b7678..cb9d748 100644 --- a/src/codingtest/codingtest.controller.ts +++ b/src/codingtest/codingtest.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, Post, Req, UseGuards, Patch, HttpException, HttpStatus } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { CodingTestService } from './codingtest.service'; import { CompileResultDto } from './dto/compileresult.dto'; @@ -32,28 +32,38 @@ export class CodingtestController { } } - @Post('/') - async getProblem(@Body('title') title: string) { - const problem = await this.codingTestService.getProblem(title); - return problem; - } - - // @Post('/getProblem') - // async getProblem(@Body('problem_number') problem: number[]) { - // const problemInfo = await this.codingTestService.getProblem(problem); - // return problemInfo; - // } - - // async - - // //FOR TESTING - // @Get('testing') - // async insertProblemToDB() { - // await this.codingTestService.insertProblemToDB(); - // } - -} + @Post('/') + async getProblem(@Body('title') title: string) { + const problem = await this.codingTestService.getProblem(title); + return problem; + } + + // @Post('/getProblem') + // async getProblem(@Body('problem_number') problem: number[]) { + // const problemInfo = await this.codingTestService.getProblem(problem); + // return problemInfo; + // } + + // async + + // //FOR TESTING + @Get('testing') + async insertProblemToDB() { + await this.codingTestService.insertProblemToDB(); + } + // @Patch('update-limit-time') + // async updateProblemLimitTime(@Body() updateData: { number: number, limitTime: number }) { + // try { + // await this.codingTestService.updateProblemLimitTime(updateData.number, updateData.limitTime); + // return { status: 'Attempted to update problem.' }; + // } catch (error) { + // console.error('An error occurred while updating the problem:', error); + // throw new HttpException('Internal server error', HttpStatus.INTERNAL_SERVER_ERROR); + // } + // } + + } /*python input = sys.readline diff --git a/src/codingtest/codingtest.service.ts b/src/codingtest/codingtest.service.ts index d984db5..0bc8d08 100644 --- a/src/codingtest/codingtest.service.ts +++ b/src/codingtest/codingtest.service.ts @@ -199,5 +199,15 @@ export class CodingTestService { console.error('An error occurred while saving the problem:', error); } } + +// async updateProblemLimitTime(problemNumber: number, limitTime: number) { +// try { +// await this.problemModel.updateOne({ number: problemNumber }, { $set: { limit_time: limitTime } }).exec(); +// console.log('Attempted to update problem.'); +// } catch (error) { +// console.error('An error occurred while updating the problem:', error); +// } +// } + } diff --git a/src/codingtest/schemas/codingtest.schema.ts b/src/codingtest/schemas/codingtest.schema.ts index 9a35818..26624e1 100644 --- a/src/codingtest/schemas/codingtest.schema.ts +++ b/src/codingtest/schemas/codingtest.schema.ts @@ -49,6 +49,9 @@ export class Problem extends Document { @Prop() @IsArray() output: string[]; + + @Prop() + limit_time: number; } export const ProblemSchema = SchemaFactory.createForClass(Problem);