From a8c3867b70f1aea94d29db2642b425b69ad9d9b7 Mon Sep 17 00:00:00 2001 From: Ethan Nguyen Date: Sat, 29 Jun 2024 06:52:51 -0700 Subject: [PATCH] Added router for pairings-model --- controllers/match-user-controller.js | 24 ++++++++++++++++++++---- routes/match-user-routes.js | 4 ++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/controllers/match-user-controller.js b/controllers/match-user-controller.js index 98ebb9c..a47ced8 100644 --- a/controllers/match-user-controller.js +++ b/controllers/match-user-controller.js @@ -53,10 +53,26 @@ const getMatchUser = async (req, res) => { // @route GET /matchUsers/getMatch // @description: Construct matches for users // @access: Private -const matching = async (req, res) => { - ///// Later call K-clusters from Flask services +const fetchMatchPairs = async (req, res) => { + try { + const response = await fetch('http://localhost:5002/matchPairs', { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error(`Error: ${response.status}`); + } + + const pairingData = await response.json(); + return res.status(200).json(pairingData); + } catch (error) { + console.error('Error fetching match pairs:', error); + return res.status(500).json({ error: 'Internal Server Error' }); + } - return res.status(201).json("Chat Matching Algo"); }; // @route POST /matchUsers @@ -204,5 +220,5 @@ module.exports = { deleteMatchUser, updateMatchUser, deleteAllMatchUsers, - matching, + fetchMatchPairs, }; diff --git a/routes/match-user-routes.js b/routes/match-user-routes.js index 260cc04..36667bb 100644 --- a/routes/match-user-routes.js +++ b/routes/match-user-routes.js @@ -8,12 +8,12 @@ const { updateMatchUser, deleteMatchUser, deleteAllMatchUsers, - matching, + fetchMatchPairs, } = require("../controllers/match-user-controller"); matchUserRouter.use(requireAuth); matchUserRouter.get("/", getMatchUsers); -matchUserRouter.get('/matching', matching) +matchUserRouter.get('/matching', fetchMatchPairs); matchUserRouter.get("/:userId", getMatchUser); matchUserRouter.post("/", createMatchUser); matchUserRouter.patch("/:userId", updateMatchUser);