Skip to content

Commit

Permalink
Merge pull request #28 from Killerrekt/master
Browse files Browse the repository at this point in the history
Changed the response of submission API to return input, expected O/P and O/P for all errors
  • Loading branch information
Mr-Emerald-Wolf authored Sep 5, 2023
2 parents 8eeb49b + c1bf9cd commit e5961a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
34 changes: 27 additions & 7 deletions api/controllers/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const testdb = require("../models/testCasesModel.js");
const axios = require("axios");
const jwt = require("jsonwebtoken");
const User = require("../models/User.js");
const { get } = require("../routes/submission.js");


class submission{
Expand Down Expand Up @@ -70,7 +71,6 @@ class submission{
memory_limit : current.memory,
})
}

const tokens = await axios.post("http://139.59.4.43:2358/submissions/batch?base64_encoded=true",
{
"submissions" : tests
Expand All @@ -86,10 +86,13 @@ class submission{
str.push(element.token);
});
const url = "http://139.59.4.43:2358/submissions/batch?tokens="+str.toString()+
"&base64_encoded=false&fields=status_id,stdout,stderr,expected_output";
"&base64_encoded=false&fields=status_id,stdout,stderr,expected_output,stdin";
console.log(url);
let completion = false;
let data_sent_back = {
input : "",
expectedOutput : "",
outputReceived :"",
error : "",
Sub_db : "",
Score : ""
Expand All @@ -110,21 +113,33 @@ class submission{
case 4:
if(element.expected_output+"\n" == element.stdout) score +=1;
else {
data_sent_back.error = "Expected output :- "+element.expected_output+ "\n but received " + element.stdout;
data_sent_back.error = element.stderr;
data_sent_back.input = element.stdin;
data_sent_back.expectedOutput = element.expected_output;
data_sent_back.outputReceived = element.stdout;
completion = true;
}
break;
case 5:
data_sent_back.error = "Time limit exceeded";
data_sent_back.error = element.stderr;
data_sent_back.input = element.stdin;
data_sent_back.expectedOutput = element.expected_output;
data_sent_back.outputReceived = element.stdout;
break;
case 6:
data_sent_back.error = "Complilation error :-" + element.stderr;
data_sent_back.error = element.stderr;
data_sent_back.input = element.stdin;
data_sent_back.expectedOutput = element.expected_output;
data_sent_back.outputReceived = element.stdout;
break;
case 13:
data_sent_back.error = "Server side error please contact the nearest admin";
break;
default:
data_sent_back.error = "Runtime error was faced :- " + element.stderr;
data_sent_back.error = element.stderr;
data_sent_back.input = element.stdin;
data_sent_back.expectedOutput = element.expected_output;
data_sent_back.outputReceived = element.stdout;
break;
}
})
Expand All @@ -140,7 +155,6 @@ class submission{

async leaderboard(req,res){
const all = await User.find({},'regNo score').sort({score:-1,updatedAt:1});
console.log(all);
res.status(200).json(all);
}

Expand Down Expand Up @@ -185,5 +199,11 @@ class submission{
}
}

async get_score(req,res){
const {regno} = req.params;
const record = await User.findOne({regNo : regno},"name regNo score");
res.status(200).json(record);
}

}
module.exports = submission;
4 changes: 2 additions & 2 deletions api/routes/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ router.get("/leaderboard",verifyAdminToken,(req,res) => {
submit.leaderboard(req,res);
})

router.get("/score/:user",verifyAdminToken,(req,res)=>{
submit.findscore(req,res);
router.get("/score/:regno",verifyAdminToken,(req,res)=>{
submit.get_score(req,res);
})

module.exports = router;
Binary file added discrete-mathematics.doc
Binary file not shown.

0 comments on commit e5961a4

Please sign in to comment.