From a672127a1306bacc58962e72aec7feb893df51a2 Mon Sep 17 00:00:00 2001 From: Muhammad Fahim Tajwar Date: Thu, 26 Sep 2024 09:29:45 +0800 Subject: [PATCH] [Unfinished] Add endpoint for CREATE question. --- .../controllers/questionController.js | 14 ++++++++++++++ backend/question-service/routes/questionRouter.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/backend/question-service/controllers/questionController.js b/backend/question-service/controllers/questionController.js index 1a295dfefb..ec8e2c3c60 100644 --- a/backend/question-service/controllers/questionController.js +++ b/backend/question-service/controllers/questionController.js @@ -29,6 +29,20 @@ exports.getMaxQuestionId = async (req, res) => { res.send(`${queryResult.id}`); } +exports.createNewQuestion = async (req, res) => { + const data = req.body; + console.log(data.id); + data.id = data.id ? data.id : await Question.findOne().sort({ id: -1}).exec().id; + const newQuestion = new Question(data); + newQuestion.save() + .then(() => { + res.send("Question successfully added"); + }) + .catch((err) => { + res.send(err) + }) +} + exports.dummyCallbackFunction = async (req, res) => { res.send("SENT A DUMMY RESPONSE"); }; \ No newline at end of file diff --git a/backend/question-service/routes/questionRouter.js b/backend/question-service/routes/questionRouter.js index 581e9f763e..58557b757f 100644 --- a/backend/question-service/routes/questionRouter.js +++ b/backend/question-service/routes/questionRouter.js @@ -14,6 +14,9 @@ questionRouter.get("/maxQuestionId", questionController.getMaxQuestionId); questionRouter.get("/byId/:questionId", questionController.getQuestionById); +questionRouter.use("/new", express.json()); +questionRouter.post("/new", questionController.createNewQuestion); + questionRouter.get("/dummy", questionController.dummyCallbackFunction); module.exports = questionRouter \ No newline at end of file