From 8327b73bffae8468f37b81ebf166cdccea529d30 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Sat, 2 Mar 2024 16:15:30 +0100 Subject: [PATCH] Stats get and post added to gateway service --- gatewayservice/gateway-service.js | 21 +++++++++++++++++++++ webapp/src/pages/Stats/Stats.js | 1 + 2 files changed, 22 insertions(+) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 05b83c2e..74e339f2 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -9,6 +9,7 @@ const port = 8000; const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002'; const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001'; const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003'; +const statsServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8004'; app.use(cors()); app.use(express.json()); @@ -52,6 +53,26 @@ app.get('/randomQuestion', async (req, res) => { } }); +app.get('/stats', async (req, res) => { + try { + // Forward the stats request to the stats service + const statsResponse = await axios.get(statsServiceUrl+'/stats', req.body); + res.json(statsResponse.data); + } catch (error) { + res.status(error.response.status).json({ error: error.response.data.error }); + } +}); + +app.post('/saveGame', async (req, res) => { + try { + // Forward the save game request to the stats service + const gameResponse = await axios.post(statsServiceUrl+'/saveGame', req.body); + res.json(gameResponse.data); + } catch (error) { + res.status(error.response.status).json({ error: error.response.data.error }); + } +}); + // Start the gateway service const server = app.listen(port, () => { console.log(`Gateway Service listening at http://localhost:${port}`); diff --git a/webapp/src/pages/Stats/Stats.js b/webapp/src/pages/Stats/Stats.js index b2a160c2..5d995b84 100644 --- a/webapp/src/pages/Stats/Stats.js +++ b/webapp/src/pages/Stats/Stats.js @@ -73,6 +73,7 @@ const Stats = () => {

Error: {error}

Por favor compruebe si los valores del formulario son correctos e inténtelo de nuevo

+