From dee6e3ce101e2fcea5338c988f4a26678d55858b Mon Sep 17 00:00:00 2001 From: Mann Patel <130435633+MannPatel0@users.noreply.github.com> Date: Fri, 18 Apr 2025 22:09:04 -0600 Subject: [PATCH] getCategory update --- backend/controllers/category.js | 25 ++++++++++++++++++ backend/index.js | 6 +++-- backend/routes/category.js | 7 +++++ backend/utils/database.js | 4 +++ .../__pycache__/app.cpython-313.pyc | Bin 5724 -> 5730 bytes 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 backend/controllers/category.js create mode 100644 backend/routes/category.js diff --git a/backend/controllers/category.js b/backend/controllers/category.js new file mode 100644 index 0000000..98a6c25 --- /dev/null +++ b/backend/controllers/category.js @@ -0,0 +1,25 @@ +const db = require("../utils/database"); + +exports.getAllCategory = async (req, res) => { + try { + const [data, fields] = await db.execute(`SELECT * FROM Category`); + + // Format as { ID: "", ID: "" } + const formattedData = {}; + data.forEach((row) => { + formattedData[row.CategoryID] = row.Name; + }); + + res.json({ + success: true, + message: "Categories fetched successfully", + data: formattedData, + }); + } catch (error) { + console.error("Error fetching categories:", error); + return res.status(500).json({ + success: false, + error: "Database error occurred", + }); + } +}; diff --git a/backend/index.js b/backend/index.js index 7afa3fe..04c623e 100644 --- a/backend/index.js +++ b/backend/index.js @@ -9,12 +9,14 @@ const searchRouter = require("./routes/search"); const recommendedRouter = require("./routes/recommendation"); const history = require("./routes/history"); const review = require("./routes/review"); +const category = require("./routes/category"); const { generateEmailTransporter } = require("./utils/mail"); const { cleanupExpiredCodes, checkDatabaseConnection, } = require("./utils/helper"); +const { getAllCategory } = require("./controllers/category"); const app = express(); @@ -42,10 +44,10 @@ app.use("/api/search", searchRouter); app.use("/api/engine", recommendedRouter); app.use("/api/history", history); app.use("/api/review", review); - +app.use("/api/category", category); // Set up a scheduler to run cleanup every hour -clean_up_time = 30*60*1000; +clean_up_time = 30 * 60 * 1000; setInterval(cleanupExpiredCodes, clean_up_time); app.listen(3030, () => { diff --git a/backend/routes/category.js b/backend/routes/category.js new file mode 100644 index 0000000..425adc6 --- /dev/null +++ b/backend/routes/category.js @@ -0,0 +1,7 @@ +const express = require("express"); +const { getAllCategory } = require("../controllers/category"); +const router = express.Router(); + +router.get("/", getAllCategory); + +module.exports = router; diff --git a/backend/utils/database.js b/backend/utils/database.js index 6e75c3a..379d5df 100644 --- a/backend/utils/database.js +++ b/backend/utils/database.js @@ -6,4 +6,8 @@ const pool = mysql.createPool({ database: "Marketplace", }); +// const pool = mysql.createPool( +// "singlestore://mann-619d0:@svc-3482219c-a389-4079-b18b-d50662524e8a-shared-dml.aws-virginia-6.svc.singlestore.com:3333/db_mann_48ba9?ssl={}", +// ); + module.exports = pool.promise(); diff --git a/recommondation-engine/__pycache__/app.cpython-313.pyc b/recommondation-engine/__pycache__/app.cpython-313.pyc index f5efd97bfd14a014c6683a8edf8f01535a1d88e2..373cb2686da6709f2f82ff2345857432f34cf2aa 100644 GIT binary patch delta 43 xcmcbk^GJvLGcPX}0}ym_GH>K=Vife!4=qkDD%Q_U%*!iCEJ@ATJcIFw2mlnr4ZHvV delta 37 rcmaE)b4Q2!GcPX}0}w>4VBE;v#K`TUpOK%Ns-K&fm$!Ky;}H=6(b)^5