From a84df6edfea7ab09714297da1cb502f7cf36e63a Mon Sep 17 00:00:00 2001 From: Hardik Pratap Singh <97048877+hardik-pratap-singh@users.noreply.github.com> Date: Wed, 15 May 2024 14:27:47 +0530 Subject: [PATCH] refactor : Refactor API endpoints into individual files. fixes #559 --- .../api-server/controllers/archive.js | 73 ++++ .../api-server/controllers/auth.js | 19 + .../api-server/controllers/feedback.js | 29 ++ .../api-server/controllers/post.js | 19 + .../api-server/controllers/predict.js | 20 + .../api-server/controllers/preference.js | 57 +++ .../api-server/controllers/reset.js | 20 + .../api-server/controllers/slur.js | 213 ++++++++++ browser-extension/api-server/index.js | 394 +----------------- .../api-server/routes/archive.js | 18 + browser-extension/api-server/routes/auth.js | 13 + .../api-server/routes/feedback.js | 13 + browser-extension/api-server/routes/post.js | 13 + .../api-server/routes/predict.js | 14 + .../api-server/routes/preference.js | 15 + browser-extension/api-server/routes/reset.js | 14 + browser-extension/api-server/routes/slur.js | 28 ++ browser-extension/plugin/manifest.json | 2 +- .../plugin/src/ui-components/pages/Slur.jsx | 2 +- 19 files changed, 591 insertions(+), 385 deletions(-) create mode 100644 browser-extension/api-server/controllers/archive.js create mode 100644 browser-extension/api-server/controllers/auth.js create mode 100644 browser-extension/api-server/controllers/feedback.js create mode 100644 browser-extension/api-server/controllers/post.js create mode 100644 browser-extension/api-server/controllers/predict.js create mode 100644 browser-extension/api-server/controllers/preference.js create mode 100644 browser-extension/api-server/controllers/reset.js create mode 100644 browser-extension/api-server/controllers/slur.js create mode 100644 browser-extension/api-server/routes/archive.js create mode 100644 browser-extension/api-server/routes/auth.js create mode 100644 browser-extension/api-server/routes/feedback.js create mode 100644 browser-extension/api-server/routes/post.js create mode 100644 browser-extension/api-server/routes/predict.js create mode 100644 browser-extension/api-server/routes/preference.js create mode 100644 browser-extension/api-server/routes/reset.js create mode 100644 browser-extension/api-server/routes/slur.js diff --git a/browser-extension/api-server/controllers/archive.js b/browser-extension/api-server/controllers/archive.js new file mode 100644 index 00000000..0600a11b --- /dev/null +++ b/browser-extension/api-server/controllers/archive.js @@ -0,0 +1,73 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); +const { + preference, + post +} = require("../db/models"); + + +const { + sendArchiveEmail, +} = require("../controller-email"); +const { encrypt, decrypt } = require("../encryption"); + + +const archiveTweet = async (req, res) => { + console.log("archive POST request"); + try { + const fileName = req.file.key; + const s3URL = req.file.location; + const { url } = req.body; + const user = req.user; + + await post.create({ + userId: user.id, + sourceUrl: url, + permanentUrl: null, + tags: null, + screenshot: fileName, + }); + + const result = await preference.findOne({ + where: { + userId: user.id, + }, + }); + resultPlain = result.get({ plain: true }); + resultPlain = { ...resultPlain, email: decrypt(resultPlain.email) }; + + console.log({ resultPlain }); + + if ( + (result != null && resultPlain.email != undefined) || + resultPlain.email != null + ) { + await sendArchiveEmail( + resultPlain.email, + url, + `https://uli-media.tattle.co.in/${fileName}` + ); + } + + res.send({ msg: "Tweet Archived" }); + } catch (err) { + res.status(501).send({ msg: "Error archiving tweet" }); + } +}; + +const getArchive = async (req, res) => { + const user = req.user; + const { rows, count } = await post.findAndCountAll({ + where: { + userId: user.id, + }, + limit: 20, + }); + + const archive = rows.map((row) => row.get({ plain: true })); + + res.send({ archive, count }); +}; + + + +module.exports = { getArchive , archiveTweet } ; diff --git a/browser-extension/api-server/controllers/auth.js b/browser-extension/api-server/controllers/auth.js new file mode 100644 index 00000000..d8964fa6 --- /dev/null +++ b/browser-extension/api-server/controllers/auth.js @@ -0,0 +1,19 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + + +const { registerAnonymousUser } = require("../controller-auth"); + + +const register = async (req, res) => { + try { + const newUser = await registerAnonymousUser(); + res.send({ user: newUser }); + } catch (err) { + console.log(err); + res.status(501).send(); + } +}; + + + +module.exports = {register} ; \ No newline at end of file diff --git a/browser-extension/api-server/controllers/feedback.js b/browser-extension/api-server/controllers/feedback.js new file mode 100644 index 00000000..5dde5800 --- /dev/null +++ b/browser-extension/api-server/controllers/feedback.js @@ -0,0 +1,29 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { + feedback +} = require("../db/models"); + + +const addFeedback = async (req, res) => { + console.log("POST feedback"); + try { + const data = req.body; + + await feedback.create({ + userId: data.user_id, + tweetText: data.tweet_text, + sentiment: data.tweet_sentiment, + confidence: data.tweet_confidence, + }); + + res.send({ msg: "Feedback Sent" }); + } catch (err) { + //console.log(err); + res.status(501).send({ msg: "Error sending feedback" }); + } +}; + + + +module.exports = {addFeedback} ; \ No newline at end of file diff --git a/browser-extension/api-server/controllers/post.js b/browser-extension/api-server/controllers/post.js new file mode 100644 index 00000000..8e234393 --- /dev/null +++ b/browser-extension/api-server/controllers/post.js @@ -0,0 +1,19 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { + post +} = require("../db/models"); + + +const getPost = async (req, res) => { + const user = req.user; + const result = post.findAll({ + where: { + userId: user.id, + }, + limit: 20, + }); + res.send({ posts: result.map((res) => res.get({ plain: true })) }); +}; + +module.exports = {getPost} ; diff --git a/browser-extension/api-server/controllers/predict.js b/browser-extension/api-server/controllers/predict.js new file mode 100644 index 00000000..df64937b --- /dev/null +++ b/browser-extension/api-server/controllers/predict.js @@ -0,0 +1,20 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { classify } = require("../service-classifier"); + + +const predict = async (req, res) => { + const { text } = req.body; + try { + const label = await classify(text); + res.send(label); + } catch (err) { + console.log("Error : could not classify tweet"); + console.log(err); + res.status(501).send("Could not label this tweet"); + } +}; + + + +module.exports = {predict} ; \ No newline at end of file diff --git a/browser-extension/api-server/controllers/preference.js b/browser-extension/api-server/controllers/preference.js new file mode 100644 index 00000000..d8f08897 --- /dev/null +++ b/browser-extension/api-server/controllers/preference.js @@ -0,0 +1,57 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { + preference +} = require("../db/models"); + +const { encrypt, decrypt } = require("../encryption"); + + +const addPreference = async (req, res) => { + console.log("POST preferences"); + const { id, language, slurList, email } = req.body; + const user = req.user; + const encryptedEmail = email ? encrypt(email) : null; + const result = await preference.upsert({ + id, + userId: user.id, + email: encryptedEmail, + language, + slurList, + }); + + let plainResult = result[0].get({ plain: true }); + console.log({ plainResult }); + res.send({ + ...plainResult, + email, + }); + + // res.send({ ...result[0].get({ plain: true }) }); +}; + + + +const getPreference = async (req, res) => { + const user = req.user; + const result = await preference.findOne({ + where: { + userId: user.id, + }, + }); + if (result == null) { + res.status(404).send(); + } else { + let plainResult = result.get({ plain: true }); + // console.log({ plainResult }); + res.send({ + ...plainResult, + email: decrypt(plainResult.email), + }); + } +}; + + + + +module.exports = {addPreference , getPreference} ; \ No newline at end of file diff --git a/browser-extension/api-server/controllers/reset.js b/browser-extension/api-server/controllers/reset.js new file mode 100644 index 00000000..9a944ad6 --- /dev/null +++ b/browser-extension/api-server/controllers/reset.js @@ -0,0 +1,20 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { resetUser } = require("../controller-auth"); + + +const resetAccount = async (req, res) => { + const { user } = req; + const userId = user.id; + console.log(`reset request for ${userId}`); + try { + await resetUser(userId); + res.send({ message: "Account reset" }); + } catch (err) { + console.log(`Error : unable to reset account`); + console.log(err); + res.status(501).send("Could not reset account"); + } +}; + +module.exports = {resetAccount} ; \ No newline at end of file diff --git a/browser-extension/api-server/controllers/slur.js b/browser-extension/api-server/controllers/slur.js new file mode 100644 index 00000000..f6dc3860 --- /dev/null +++ b/browser-extension/api-server/controllers/slur.js @@ -0,0 +1,213 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const { + slur, + category, + sequelize, +} = require("../db/models"); + + +console.log(`Inside Slur : ${process.env.NODE_ENV}`); + +// GET request for Slur and Category +const getSlur = async (req, res) => { + const user = req.user; + try { + const results = await slur.findAll({ + where: { + userId: user.id, + }, + include: [ + { + model: category, + as: "categories", + }, + ], + }); + res.json(results); + } catch (error) { + console.error(error); + res.status(500).send({ error: "server error" }); + } +}; + +// GET request for Slur and Category by slurId +const getSlurById = async (req, res) => { + const slurId = req.params.id; + try { + const slurMetadata = await slur.findByPk(slurId, { + include: [ + { + model: category, + as: "categories", + }, + ], + }); + res.json(slurMetadata); + } catch (error) { + console.error(error); + res.status(500).send({ error: "server error" }); + } +}; + +// POST request for slur and category +const createSlur = async (req, res) => { + const { user } = req; + const userId = user.id; + const { + label, + levelOfSeverity, + casual, + appropriated, + appropriationContext, + labelMeaning, + categories, + } = req.body; + console.log( + userId, + label, + labelMeaning, + appropriated, + appropriationContext, + categories + ); + const t = await sequelize.transaction(); + + try { + const newSlur = await slur.create( + { + userId, + label, + levelOfSeverity, + casual, + appropriated, + appropriationContext, + labelMeaning, + }, + { transaction: t } + ); + + const categoryPromises = categories.map(async (categoryData) => { + const newCategory = await category.create( + { + slurId: newSlur.id, + category: categoryData, + }, + { transaction: t } + ); + return newCategory; + }); + + const createdCategories = await Promise.all(categoryPromises); + + await t.commit(); + + res.send({ + slur: newSlur, + categories: createdCategories, + }); + } catch (error) { + await t.rollback(); + console.error(error); + res.status(500).send({ error: "server error" }); + } +}; + +// PUT request for slur and category +const updateSlur = async (req, res) => { + const slurId = req.params.id; + const { + label, + levelOfSeverity, + casual, + appropriated, + appropriationContext, + labelMeaning, + categories, + } = req.body; + const t = await sequelize.transaction(); + + try { + const existingSlur = await slur.findByPk(slurId, { transaction: t }); + if (!existingSlur) { + res.status(404).send({ error: "Slur not found" }); + await t.rollback(); + return; + } + // Update the slur record + existingSlur.label = label; + existingSlur.levelOfSeverity = levelOfSeverity; + existingSlur.casual = casual; + existingSlur.appropriated = appropriated; + existingSlur.appropriationContext = appropriationContext; + existingSlur.labelMeaning = labelMeaning; + await existingSlur.save({ transaction: t }); + + // Delete existing categories for this slur + await category.destroy({ + where: { + slurId: existingSlur.id, + }, + transaction: t, + }); + + // Create new categories + const categoryPromises = categories.map(async (categoryData) => { + const newCategory = await category.create( + { + slurId: existingSlur.id, + category: categoryData, + }, + { transaction: t } + ); + return newCategory; + }); + + const updatedCategories = await Promise.all(categoryPromises); + await t.commit(); + + res.send({ + slur: existingSlur, + categories: updatedCategories, + }); + } catch (error) { + console.error(error); + await t.rollback(); + res.status(500).send({ error: "Server error" }); + } +}; + +// DELETE request for slur and category +const deleteSlur = async (req, res) => { + const slurId = req.params.id; + const t = await sequelize.transaction(); + try { + const slurToDelete = await slur.findByPk(slurId, { transaction: t }); + if (!slurToDelete) { + res.status(404).send({ error: "Slur not found" }); + await t.rollback(); + return; + } + + await category.destroy({ + where: { + slurId: slurToDelete.id, + }, + transaction: t, + }); + await slurToDelete.destroy({ transaction: t }); + + await t.commit(); + + res.send(); + } catch (error) { + console.error(error); + await t.rollback(); + res.status(500).send({ error: "server error" }); + } +}; + + + + +module.exports = {getSlur , getSlurById , createSlur , updateSlur , deleteSlur} \ No newline at end of file diff --git a/browser-extension/api-server/index.js b/browser-extension/api-server/index.js index 09f25ec9..d24154a5 100644 --- a/browser-extension/api-server/index.js +++ b/browser-extension/api-server/index.js @@ -5,398 +5,26 @@ const app = express(); app.disable("x-powered-by"); const port = 3000; const cors = require("cors"); -const { upload } = require("./s3"); - -const { - preference, - post, - feedback, - slur, - category, - sequelize, -} = require("./db/models"); - -const { registerAnonymousUser, resetUser } = require("./controller-auth"); -const { sendEmail } = require("./email"); -const { - sendArchiveEmail, - sendAskFriendsForHelpEmail, -} = require("./controller-email"); const { authentication } = require("./middlewares"); -const { encrypt, decrypt } = require("./encryption"); -const { classify } = require("./service-classifier"); -const { text } = require("express"); +app.use(authentication); + app.use(cors()); app.use(express.json()); app.options("*", cors()); -app.use(authentication); - -console.log(`Environment : ${process.env.NODE_ENV}`); -app.get("/auth/register", async (req, res) => { - try { - const newUser = await registerAnonymousUser(); - res.send({ user: newUser }); - } catch (err) { - console.log(err); - res.status(501).send(); - } -}); - -app.post("/preference/", async (req, res) => { - console.log("POST preferences"); - const { id, language, slurList, email } = req.body; - const user = req.user; - const encryptedEmail = email ? encrypt(email) : null; - const result = await preference.upsert({ - id, - userId: user.id, - email: encryptedEmail, - language, - slurList, - }); - - let plainResult = result[0].get({ plain: true }); - console.log({ plainResult }); - res.send({ - ...plainResult, - email, - }); - - // res.send({ ...result[0].get({ plain: true }) }); -}); - -// Feedback code from here -app.post("/feedback", async (req, res) => { - console.log("POST feedback"); - try { - const data = req.body; - - await feedback.create({ - userId: data.user_id, - tweetText: data.tweet_text, - sentiment: data.tweet_sentiment, - confidence: data.tweet_confidence, - }); - - res.send({ msg: "Feedback Sent" }); - } catch (err) { - //console.log(err); - res.status(501).send({ msg: "Error sending feedback" }); - } -}); - -// Feedback code ends here -app.get("/preference/", async (req, res) => { - const user = req.user; - const result = await preference.findOne({ - where: { - userId: user.id, - }, - }); - if (result == null) { - res.status(404).send(); - } else { - let plainResult = result.get({ plain: true }); - // console.log({ plainResult }); - res.send({ - ...plainResult, - email: decrypt(plainResult.email), - }); - } -}); - -app.get("/post", async (req, res) => { - const user = req.user; - const result = post.findAll({ - where: { - userId: user.id, - }, - limit: 20, - }); - res.send({ posts: result.map((res) => res.get({ plain: true })) }); -}); - -app.post("/archive", upload.single("screenshot"), async (req, res) => { - console.log("archive POST request"); - try { - const fileName = req.file.key; - const s3URL = req.file.location; - const { url } = req.body; - const user = req.user; - - await post.create({ - userId: user.id, - sourceUrl: url, - permanentUrl: null, - tags: null, - screenshot: fileName, - }); - - const result = await preference.findOne({ - where: { - userId: user.id, - }, - }); - resultPlain = result.get({ plain: true }); - resultPlain = { ...resultPlain, email: decrypt(resultPlain.email) }; - - console.log({ resultPlain }); - - if ( - (result != null && resultPlain.email != undefined) || - resultPlain.email != null - ) { - await sendArchiveEmail( - resultPlain.email, - url, - `https://uli-media.tattle.co.in/${fileName}` - ); - } - - res.send({ msg: "Tweet Archived" }); - } catch (err) { - res.status(501).send({ msg: "Error archiving tweet" }); - } -}); - -app.get("/archive", async (req, res) => { - const user = req.user; - const { rows, count } = await post.findAndCountAll({ - where: { - userId: user.id, - }, - limit: 20, - }); - const archive = rows.map((row) => row.get({ plain: true })); +app.use("/" , require("./routes/slur.js")) ; +app.use("/" , require('./routes/archive.js')) ; +app.use("/" , require('./routes/reset.js')) ; +app.use("/" , require('./routes/preference.js')) ; +app.use("/" , require('./routes/predict.js')) ; +app.use("/" , require('./routes/post.js')) ; +app.use("/" , require('./routes/auth.js')) ; +app.use("/" , require('./routes/feedback.js')) ; - res.send({ archive, count }); -}); - -app.post("/predict", async (req, res) => { - const { text } = req.body; - try { - const label = await classify(text); - res.send(label); - } catch (err) { - console.log("Error : could not classify tweet"); - console.log(err); - res.status(501).send("Could not label this tweet"); - } -}); - -app.post("/reset", async (req, res) => { - const { user } = req; - const userId = user.id; - console.log(`reset request for ${userId}`); - try { - await resetUser(userId); - res.send({ message: "Account reset" }); - } catch (err) { - console.log(`Error : unable to reset account`); - console.log(err); - res.status(501).send("Could not reset account"); - } -}); - -// GET request for Slur and Category -app.get("/slur", async (req, res) => { - const user = req.user; - try { - const results = await slur.findAll({ - where: { - userId: user.id, - }, - include: [ - { - model: category, - as: "categories", - }, - ], - }); - res.json(results); - } catch (error) { - console.error(error); - res.status(500).send({ error: "server error" }); - } -}); - -app.get("/slur/:id", async (req, res) => { - const slurId = req.params.id; - try { - const slurMetadata = await slur.findByPk(slurId, { - include: [ - { - model: category, - as: "categories", - }, - ], - }); - res.json(slurMetadata); - } catch (error) { - console.error(error); - res.status(500).send({ error: "server error" }); - } -}); - -// POST request for slur and category -app.post("/slur/create", async (req, res) => { - const { user } = req; - const userId = user.id; - const { - label, - levelOfSeverity, - casual, - appropriated, - appropriationContext, - labelMeaning, - categories, - } = req.body; - console.log( - userId, - label, - labelMeaning, - appropriated, - appropriationContext, - categories - ); - const t = await sequelize.transaction(); - - try { - const newSlur = await slur.create( - { - userId, - label, - levelOfSeverity, - casual, - appropriated, - appropriationContext, - labelMeaning, - }, - { transaction: t } - ); - - const categoryPromises = categories.map(async (categoryData) => { - const newCategory = await category.create( - { - slurId: newSlur.id, - category: categoryData, - }, - { transaction: t } - ); - return newCategory; - }); - - const createdCategories = await Promise.all(categoryPromises); - - await t.commit(); - - res.send({ - slur: newSlur, - categories: createdCategories, - }); - } catch (error) { - await t.rollback(); - console.error(error); - res.status(500).send({ error: "server error" }); - } -}); - -// PUT request for slur and category -app.put("/slur/:id", async (req, res) => { - const slurId = req.params.id; - const { - label, - levelOfSeverity, - casual, - appropriated, - appropriationContext, - labelMeaning, - categories, - } = req.body; - const t = await sequelize.transaction(); - - try { - const existingSlur = await slur.findByPk(slurId, { transaction: t }); - if (!existingSlur) { - res.status(404).send({ error: "Slur not found" }); - await t.rollback(); - return; - } - // Update the slur record - existingSlur.label = label; - existingSlur.levelOfSeverity = levelOfSeverity; - existingSlur.casual = casual; - existingSlur.appropriated = appropriated; - existingSlur.appropriationContext = appropriationContext; - existingSlur.labelMeaning = labelMeaning; - await existingSlur.save({ transaction: t }); - - // Delete existing categories for this slur - await category.destroy({ - where: { - slurId: existingSlur.id, - }, - transaction: t, - }); - - // Create new categories - const categoryPromises = categories.map(async (categoryData) => { - const newCategory = await category.create( - { - slurId: existingSlur.id, - category: categoryData, - }, - { transaction: t } - ); - return newCategory; - }); - - const updatedCategories = await Promise.all(categoryPromises); - await t.commit(); - - res.send({ - slur: existingSlur, - categories: updatedCategories, - }); - } catch (error) { - console.error(error); - await t.rollback(); - res.status(500).send({ error: "Server error" }); - } -}); - -// DELETE request for slur and category -app.delete("/slur/:id", async (req, res) => { - const slurId = req.params.id; - const t = await sequelize.transaction(); - try { - const slurToDelete = await slur.findByPk(slurId, { transaction: t }); - if (!slurToDelete) { - res.status(404).send({ error: "Slur not found" }); - await t.rollback(); - return; - } - - await category.destroy({ - where: { - slurId: slurToDelete.id, - }, - transaction: t, - }); - await slurToDelete.destroy({ transaction: t }); - - await t.commit(); +console.log(`Environment : ${process.env.NODE_ENV}`); - res.send(); - } catch (error) { - console.error(error); - await t.rollback(); - res.status(500).send({ error: "server error" }); - } -}); app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`); diff --git a/browser-extension/api-server/routes/archive.js b/browser-extension/api-server/routes/archive.js new file mode 100644 index 00000000..0146b5aa --- /dev/null +++ b/browser-extension/api-server/routes/archive.js @@ -0,0 +1,18 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router() ; + +const { upload } = require("../s3"); + + +const {getArchive , archiveTweet} = require("../controllers/archive.js") ; + + + +router.get("/archive", getArchive); +router.post("/archive", upload.single("screenshot"), archiveTweet); + + + +module.exports = router ; diff --git a/browser-extension/api-server/routes/auth.js b/browser-extension/api-server/routes/auth.js new file mode 100644 index 00000000..15da1171 --- /dev/null +++ b/browser-extension/api-server/routes/auth.js @@ -0,0 +1,13 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const { register } = require("../controllers/auth"); + + +router.get("/auth/register", register); + + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/api-server/routes/feedback.js b/browser-extension/api-server/routes/feedback.js new file mode 100644 index 00000000..6568122b --- /dev/null +++ b/browser-extension/api-server/routes/feedback.js @@ -0,0 +1,13 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const { addFeedback } = require("../controllers/feedback"); + + +router.post("/feedback", addFeedback); + + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/api-server/routes/post.js b/browser-extension/api-server/routes/post.js new file mode 100644 index 00000000..a16074b2 --- /dev/null +++ b/browser-extension/api-server/routes/post.js @@ -0,0 +1,13 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const { getPost } = require("../controllers/post"); + + +router.get("/post", getPost); + + +module.exports = router ; diff --git a/browser-extension/api-server/routes/predict.js b/browser-extension/api-server/routes/predict.js new file mode 100644 index 00000000..50785610 --- /dev/null +++ b/browser-extension/api-server/routes/predict.js @@ -0,0 +1,14 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const {predict} = require("../controllers/predict") ; + + +router.post("/predict", predict); + + + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/api-server/routes/preference.js b/browser-extension/api-server/routes/preference.js new file mode 100644 index 00000000..3d147c0b --- /dev/null +++ b/browser-extension/api-server/routes/preference.js @@ -0,0 +1,15 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const { addPreference, getPreference } = require("../controllers/preference"); + + +router.get("/preference/", getPreference); +router.post("/preference/", addPreference); + + + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/api-server/routes/reset.js b/browser-extension/api-server/routes/reset.js new file mode 100644 index 00000000..171999b7 --- /dev/null +++ b/browser-extension/api-server/routes/reset.js @@ -0,0 +1,14 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router(); + + +const { resetUser } = require("../controller-auth"); +const { resetAccount } = require("../controllers/reset"); + + + +router.post("/reset", resetAccount); + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/api-server/routes/slur.js b/browser-extension/api-server/routes/slur.js new file mode 100644 index 00000000..4e0cbb64 --- /dev/null +++ b/browser-extension/api-server/routes/slur.js @@ -0,0 +1,28 @@ +//console.log(`Environment : ${process.env.NODE_ENV}`); + +const express = require("express"); +const router = express.Router() ; + + +const {getSlur , getSlurById , createSlur , updateSlur , deleteSlur } = require("../controllers/slur") + + +console.log(`Inside Slur : ${process.env.NODE_ENV}`); + +// GET request for Slur and Category +router.get("/slur", getSlur); + +// GET request for Slur and Category by slurId +router.get("/slur/:id", getSlurById); + +// POST request for slur and category +router.post("/slur/create", createSlur); + +// PUT request for slur and category +router.put("/slur/:id", updateSlur); + +// DELETE request for slur and category +router.delete("/slur/:id", deleteSlur); + + +module.exports = router ; \ No newline at end of file diff --git a/browser-extension/plugin/manifest.json b/browser-extension/plugin/manifest.json index a457ab43..b379ef8a 100644 --- a/browser-extension/plugin/manifest.json +++ b/browser-extension/plugin/manifest.json @@ -23,4 +23,4 @@ "default_popup": "options.html" }, "icons": { "16": "icon16.png", "48": "icon32.png" } -} +} \ No newline at end of file diff --git a/browser-extension/plugin/src/ui-components/pages/Slur.jsx b/browser-extension/plugin/src/ui-components/pages/Slur.jsx index 6e1889a4..cf3de41f 100644 --- a/browser-extension/plugin/src/ui-components/pages/Slur.jsx +++ b/browser-extension/plugin/src/ui-components/pages/Slur.jsx @@ -188,4 +188,4 @@ export function Slur() { ); -} +} \ No newline at end of file