generated from CodeChefVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #8 from Killerrekt/master
Submission API PR
- Loading branch information
Showing
7 changed files
with
356 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
# Environment | ||
.env | ||
|
||
/node_modules | ||
/node_modules |
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,35 @@ | ||
const submission_db = require("../models/submission.js"); | ||
const questiondb = require("../models/ques.js"); | ||
const testdb = require("../models/testCasesModel.js"); | ||
|
||
class submission{ | ||
async create(req,res){ | ||
const {user,language,code,question_id} = req.body; | ||
await submission_db.create({user : user, language : language, code : code, question_id : question_id}) | ||
.then(() => console.log("Data has been entered into the DB")).catch(err => console.log(err)); | ||
res.sendStatus(201); | ||
} | ||
|
||
async getdata(req,res){ | ||
const {question_id,code,language_id} = req.body; | ||
const testcase = await questiondb.findById(question_id,'testCases'); | ||
for(let i = 0;i<testcase.length;i++){ | ||
const current = await testdb.findById(testcase[i]); | ||
const data_sent_to_judge0 = { | ||
source_code : code, | ||
language_id : language_id, | ||
stdin : current.input, | ||
expected_output : current.expectedOutput, | ||
cpu_time_limit : current.time, | ||
memory_limit : current.memory, | ||
} | ||
//now this data_sent_to_judge0 can be sent to the get submission route of judge0 API and that will return a token | ||
//it can then use the given token to post the submission to see the results | ||
console.log(data_sent_to_judge0); | ||
} | ||
res.sendStatus(200);//in near future need to add the score to a score schema so status will turn to 201 and hence request is a post | ||
//need to test this function call | ||
} | ||
} | ||
|
||
module.exports = submission; |
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,14 @@ | ||
const {Schema,model} = require("mongoose"); | ||
|
||
const submission_schema = new Schema({ | ||
user : {type:Number,required:true}, | ||
language : {type:String,required:true}, | ||
code : {type:String,required:true}, | ||
pass : {type:Boolean,required:true,default:false}, | ||
question_id : {type:Number}}, //this will act as an indicator to which question in the question DB shld be tested against the code | ||
{timestamps : true} | ||
); | ||
|
||
const submission_db = model("Submissions",submission_schema); | ||
|
||
module.exports = submission_db; |
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,19 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const submission = require("../controllers/submission.js"); | ||
|
||
const submit = new submission; | ||
|
||
router.use(express.json()); | ||
router.use(express.urlencoded()) | ||
|
||
router.post('/create', (req, res) => { | ||
//console.log("The route worked"); | ||
submit.create(req,res); | ||
}) | ||
|
||
router.post("/test",(req,res) =>{ | ||
submit.getdata(req,res); | ||
}) | ||
|
||
module.exports = router |
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
Oops, something went wrong.