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 f5efd97..373cb26 100644 Binary files a/recommondation-engine/__pycache__/app.cpython-313.pyc and b/recommondation-engine/__pycache__/app.cpython-313.pyc differ