Skip to content

Commit

Permalink
Merge pull request #225 from navgurukul/feature/test-cases-api
Browse files Browse the repository at this point in the history
Added the errorhandler, helpers and move the common function to helpe…
  • Loading branch information
giribabu22 authored Aug 6, 2024
2 parents 4b578ed + d216a81 commit 9a30f1e
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 308 deletions.
7 changes: 7 additions & 0 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3549,6 +3549,7 @@ export const zuvyCodingQuestions = main.table("zuvy_coding_questions", {
description: text("description").notNull(),
difficulty: varchar("difficulty", { length: 50 }),
content: jsonb("content"),
constraints: text("constraints"),
usage: integer("usage"),
tagId: integer("tag_id").references(() => zuvyTags.id),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow(),
Expand All @@ -3570,6 +3571,12 @@ export const zuvyTestCases = main.table("zuvy_test_cases", {
inputs: jsonb("inputs").notNull(),
expectedOutput: jsonb("expected_output").notNull(),
});
export const zuvyCodingQuestionsRelation = relations(zuvyTestCases, ({one, many}) => ({
codingQuestion: one(zuvyCodingQuestions, {
fields: [zuvyTestCases.questionId],
references: [zuvyCodingQuestions.id],
}),
}))

export const zuvyPracticeCodeRelation = relations(zuvyPracticeCode, ({one, many}) => ({
codingQuestion: one(zuvyCodingQuestions, {
Expand Down
69 changes: 1 addition & 68 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,4 @@ export const ConfigIndex = {
password: process.env.DB_PASS,
database: process.env.DB_NAME,
},
};

export const typeMappings = {
java: {
int: 'int',
float: 'float',
double: 'double',
str: 'String',
arrayOfnum: 'int[]', // This is an example; it can be modified based on the array type
arrayOfStr: 'String[]', // This is an example; it can be modified based on the array type
returnType: 'int', // Default return type, modify as needed
defaultReturnValue: '0', // Default return value, modify as needed
inputType: (parameterType) => {
switch(parameterType) {
case 'int': return 'Int';
case 'float': return 'Float';
case 'double': return 'Double';
case 'str': return 'Line'; // For reading a whole line of string input
default: return 'Int'; // Default input type, modify as needed
}
}
},
python: {
int: 'int',
float: 'float',
str: 'str',
arrayOfnum: 'List[int]', // This is an example; it can be modified based on the arrayOfnum type
arrayOfStr: 'List[str]', // This is an example; it can be modified based on the arrayOfStr type
input: (parameterType) => {
switch(parameterType) {
case 'int': return 'int(input())';
case 'float': return 'float(input())';
case 'str': return 'input()';
default: return 'int(input())'; // Default input type, modify as needed
}
}
},
c: {
int: 'int',
float: 'float',
double: 'double',
str: 'char*',
arrayOfnum: 'int[]', // This is an example; it can be modified based on the arrayOfnum type
arrayOfStr: 'char**', // This is an example; it can be modified based on the arrayOfStr type
returnType: 'int', // Default return type, modify as needed
defaultReturnValue: '0', // Default return value, modify as needed
},
cpp: {
int: 'int',
float: 'float',
double: 'double',
str: 'string',
arrayOfnum: 'vector<int>', // This is an example; it can be modified based on the arrayOfnum type
arrayOfStr: 'vector<string>', // This is an example; it can be modified based on the arrayOfStr type
returnType: 'int', // Default return type, modify as needed
defaultReturnValue: '0', // Default return value, modify as needed
},
javascript: {
int: 'number',
float: 'number',
double: 'number',
str: 'string',
arrayOfnum: 'number[]', // This is an example; it can be modified based on the arrayOfnum type
arrayOfStr: 'string[]', // This is an example; it can be modified based on the arrayOfStr type
returnType: 'number', // Default return type, modify as needed
defaultReturnValue: '0', // Default return value, modify as needed
}
};
};
2 changes: 1 addition & 1 deletion src/controller/batches/batch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ export class BatchesService {

async deleteBatch(id: number) {
try {
let data = await db.delete(zuvyBatches).where(eq(zuvyBatches.id, id)).returning();
await db
.update(zuvyBatchEnrollments)
.set({ batchId: null })
.where(eq(zuvyBatchEnrollments.batchId, id))
.returning();
let data = await db.delete(zuvyBatches).where(eq(zuvyBatches.id, id)).returning();
if (data.length === 0) {
return [
{ status: 'error', message: 'Batch not found', code: 404 },
Expand Down
70 changes: 35 additions & 35 deletions src/controller/codingPlatform/codingPlatform.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,6 @@ export class CodingPlatformController {
return this.codingPlatformService.getQuestionsWithStatus(req.user[0].id, difficulty, page, limit);
}

@Get('questionById/:questionId')
@ApiOperation({ summary: 'Get the questions by Id' })
@ApiBearerAuth()
async getQuestionById(@Param('questionId') questionId: number) {
return this.codingPlatformService.getQuestionById(questionId);
}

// @Post('createCodingQuestion')
// @ApiOperation({ summary: 'Create coding question' })
// @ApiBearerAuth()
// async createCodingProblems(@Body() createCodingQuestion: CreateProblemDto) {
// let examples = [];
// let testCases = [];
// for (let i = 0; i < createCodingQuestion.examples.length; i++) {
// examples.push(createCodingQuestion.examples[i].inputs);
// }
// createCodingQuestion.examples = examples;
// for (let j = 0; j < createCodingQuestion.testCases.length; j++) {
// testCases.push(createCodingQuestion.testCases[j].inputs)
// }
// createCodingQuestion.testCases = testCases
// return this.codingPlatformService.createCodingProblem(createCodingQuestion);
//
// }

@Post('/practicecode/questionId=:questionId')
@ApiOperation({ summary: 'Submiting the coding question' })
Expand Down Expand Up @@ -160,45 +136,69 @@ export class CodingPlatformController {
@Post('create-question')
@ApiOperation({ summary: 'Create coding question with test cases' })
@ApiBearerAuth()
async createCodingQuestion(@Body() createCodingQuestionDto: CreateProblemDto) {
return this.codingPlatformService.createCodingQuestion(createCodingQuestionDto);
async createCodingQuestion(@Body() createCodingQuestionDto: CreateProblemDto) : Promise<any>{
let [err, data] = await this.codingPlatformService.createCodingQuestion(createCodingQuestionDto);
if (err) {
throw new BadRequestException(err);
}
return data;
}

@Put('update-question/:id')
@ApiOperation({ summary: 'Update coding question' })
@ApiBearerAuth()
async updateCodingQuestion(@Param('id') id: number, @Body() updateCodingQuestionDto: updateProblemDto) {
return this.codingPlatformService.updateCodingQuestion(id, updateCodingQuestionDto);
let [err, data] = await this.codingPlatformService.updateCodingQuestion(id, updateCodingQuestionDto);
if (err) {
throw new BadRequestException(err);
}
return data;
}

@Delete('delete-question/:id')
@ApiOperation({ summary: 'Delete coding question' })
@ApiBearerAuth()
async deleteCodingQuestion(@Param('id') id: number) {
return this.codingPlatformService.deleteCodingQuestion(id);
async deleteCodingQuestion(@Param('id') id: number): Promise<any> {
let [err, data] = await this.codingPlatformService.deleteCodingQuestion(id);
if (err) {
throw new BadRequestException(err);
}
return data;
}

@Delete('delete-testcase/:id')
@ApiOperation({ summary: 'Delete coding Testcase' })
@ApiBearerAuth()
async deleteCodingTestcase(@Param('id') id: number) {
return this.codingPlatformService.deleteCodingTestcase(id);
async deleteCodingTestcase(@Param('id') id: number): Promise<any> {
let [err, data] = await this.codingPlatformService.deleteCodingTestcase(id);
if (err) {
throw new BadRequestException(err);
}
return data;
}

// get coding question by id
@Get('get-coding-question/:id')
@ApiOperation({ summary: 'Get coding question' })
@ApiBearerAuth()
async getCodingQuestion(@Param('id') Id: number) {
return this.codingPlatformService.getCodingQuestion(Id);
async getCodingQuestion(@Param('id') Id: number): Promise<any> {
let [err, data] = await this.codingPlatformService.getCodingQuestion(Id);
if (err) {
throw new BadRequestException(err);
}
return data;
}

// adding the test case by question id
@Post('add-test-case/:question_id')
@ApiOperation({ summary: 'Add test case to coding question' })
@ApiBearerAuth()
async addTestCase(@Param('question_id') question_id: number, @Body() updateTestCaseDto: TestCaseDto) {
return this.codingPlatformService.addTestCase(question_id, updateTestCaseDto);
async addTestCase(@Param('question_id') question_id: number, @Body() updateTestCaseDto: TestCaseDto): Promise<any> {
let [err, data] = await this.codingPlatformService.addTestCase(question_id, updateTestCaseDto);
if (err) {
throw new BadRequestException(err);
}
return data;
}

}
Loading

0 comments on commit 9a30f1e

Please sign in to comment.