diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 7b96b97..229cd8b 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -127,6 +127,27 @@ app.get('/rankings/:filter', async (req, res) => { } }); + +app.get('/ranking/user', async (req, res) => { + const username = req.query.username; + const category = req.query.category; + + try { + // Forward the request to the user service + const result = await axios.get(`${userServiceUrl}/ranking/user`, { + params: { + username: username, + category: category + } + }); + + res.json(result.data); + + } catch (error) { + res.status(error.response.status).json({ error: error.response.data.error }); + } +}); + // Read the OpenAPI YAML file synchronously openapiPath='./openapi.yaml' if (fs.existsSync(openapiPath)) { diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 521ab55..a8989c6 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -54,6 +54,38 @@ app.get('/rankings/:filter', async (req, res) => { }) +// Get the ranking info for a specified category and user +app.get('/ranking/user', async (req, res) => { + const username = req.query.username; + const category = req.query.category; + + try { + // Fetch the user with the specified username + const user = await User.findOne({ username }); + + // If user not found, return error + if (!user) { + return res.status(400).json("Error: User not found"); + } + + // Extract ranking info for the specified category + const rankingInfo = { + username: user.username, + category, + points: user.ranking[category].points, + questions: user.ranking[category].questions, + correct: user.ranking[category].correct, + wrong: user.ranking[category].wrong + }; + + res.status(200).json(rankingInfo); + } catch (error) { + res.status(400).json({ error: error.message }); + } +}); + + + app.post("/addpoints", async (req, res) => { const username = req.body.username; const category = req.body.category; diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index d00172c..ad9e64f 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -15,7 +15,7 @@ defineFeature(feature, test => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch() - : await puppeteer.launch({ headless: false, slowMo:5 }); + : await puppeteer.launch({ headless: false, slowMo:60 }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }) diff --git a/webapp/src/App.jsx b/webapp/src/App.jsx index fdc7ba8..93dbea8 100644 --- a/webapp/src/App.jsx +++ b/webapp/src/App.jsx @@ -7,6 +7,8 @@ import RankingsLayout from './components/ranking/RankingLayout'; import Game from './components/Game'; import MainPage from './components/MainPage'; import Squads from './components/Squads'; +import UserProfile from './components/UserProfile'; + function App() { // const isAuthenticated = useIsAuthenticated() // True if user has logged in @@ -25,6 +27,7 @@ function App() { } /> } /> } /> + } /> ) diff --git a/webapp/src/components/Navbar.jsx b/webapp/src/components/Navbar.jsx index 8c92c81..f6b49fa 100644 --- a/webapp/src/components/Navbar.jsx +++ b/webapp/src/components/Navbar.jsx @@ -12,6 +12,7 @@ function Navbar() { } return ( +