Skip to content

Commit

Permalink
v1 added
Browse files Browse the repository at this point in the history
  • Loading branch information
ssxdev committed Nov 14, 2022
1 parent 905c1c6 commit 138962c
Show file tree
Hide file tree
Showing 9 changed files with 8,008 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Code/
Code
node_modules
94 changes: 94 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const request = require('request');
const alert = require('alert');

const app = express();

app.set("view engine", "ejs");

app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));

mongoose.connect("mongodb://localhost:27017/compilerDB");

const testCaseSchema = new mongoose.Schema({
testCase: String
});

const TestCase = mongoose.model("TestCase", testCaseSchema);

const problemSchema = new mongoose.Schema({
question: String,
input: [testCaseSchema],
output: String,
soltuion: String,
time: String,
memory: String
});

const Problem = mongoose.model("Problem", problemSchema);

app.get("/", function(req, res) {
res.render("body");
});

app.get("/teacher", function(req, res) {
res.render("teacher");
});

app.post("/teacher", function(req, res) {
const question = req.body.question;
const solution = req.body.solution;
const testCase = req.body.testCase;
const hiddenTestCase = req.body.hiddenTestCase;

const newTestCase = new TestCase({
testCase: testCase
});
const newHiddenTestCase = new TestCase({
hiddenTestCase: hiddenTestCase
});

var program = {
script : solution,
stdin: testCase,
language: "cpp14",
versionIndex: "0",
clientId: "",
clientSecret:""
};
request({
url: 'https://api.jdoodle.com/v1/execute',
method: "POST",
json: program
},
function (error, response, body) {
if(error) { console.log('error:', error); }
const output = body.output;
const memory = body.memory;
const time = body.cpuTime;

const newProblem = new Problem({
question: question,
input: [newTestCase],
output: output,
soltuion: solution,
time: time,
memory: memory
});

alert("Question Uploaded!");

newProblem.save();
});

res.redirect("/teacher");
});



app.listen(3000, function() {
console.log("Server is running on port 3000.");
});
Loading

0 comments on commit 138962c

Please sign in to comment.