From d12d0e2bf06837e3d54c49489ba00a2ff6de50f5 Mon Sep 17 00:00:00 2001 From: Marco Quintana Date: Thu, 4 Apr 2024 19:37:23 +0200 Subject: [PATCH 1/5] Changed from distributed monolith to microservices --- gatewayservice/gateway-service.js | 24 +++++++++++++++---- .../questiongenerator-service.js | 6 ++++- storeQuestionService/store-q-service.js | 6 ++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 30bfd2c6..1c77619a 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -17,6 +17,20 @@ app.use(express.json()); //Prometheus configuration const metricsMiddleware = promBundle({includeMethod: true}); + +function catchAction(error, res) { + if ('response' in error && 'status' in error.response && 'data' in error.response && 'error' in error.response.data) + res.status(error.response.status).json({ error: error.response.data.error }); + else if('response' in error && 'status'){ + res.status(error.response.status).json({ error: 'Unknown error' }); + } else { + console.log("Unknown error: " + error); + } + // } else { + // res.status(500).json({ error: 'Internal server error' }); + // } +} + app.use(metricsMiddleware); // Health check endpoint @@ -30,7 +44,7 @@ app.post('/login', async (req, res) => { const authResponse = await axios.post(authServiceUrl+'/login', req.body); res.json(authResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); + catchAction(error, res); } }); @@ -40,7 +54,7 @@ app.post('/adduser', async (req, res) => { const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); res.json(userResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); + catchAction(error, res) } }); @@ -51,7 +65,7 @@ app.get('/history/games/:username', async (req, res) => { const response = await axios.get(url); res.json(response.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); + catchAction(error, res) } }) @@ -60,7 +74,7 @@ app.get('/history/questions', async (req, res) => { const response = await axios.get(storeQuestionsServiceUrl+'/history/questions'); res.json(response.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); + catchAction(error, res) } }) @@ -69,7 +83,7 @@ app.get(`/questions`, async (req, res) => { const response = await axios.get(questionsGeneratorServiceUrl+`/questions`); res.json(response.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); + catchAction(error, res) } }) diff --git a/questionsservice/questiongeneratorservice/questiongenerator-service.js b/questionsservice/questiongeneratorservice/questiongenerator-service.js index 852ddd16..ca384971 100644 --- a/questionsservice/questiongeneratorservice/questiongenerator-service.js +++ b/questionsservice/questiongeneratorservice/questiongenerator-service.js @@ -76,7 +76,11 @@ app.get('/questions', async (req, res) => { // const questions = await Question.find() const defaultQuestion = await getQuestions(req); - const questionsHistoryResponse = await axios.post(questionHistoryServiceUrl + '/history/questions', defaultQuestion); + try{ + const questionsHistoryResponse = await axios.post(questionHistoryServiceUrl + '/history/questions', defaultQuestion); + } catch (error) { + console.error(`Error saving questions history: ${error}`); + } res.json(defaultQuestion); } catch (error) { // res.status(500).json({ message: error.message }) diff --git a/storeQuestionService/store-q-service.js b/storeQuestionService/store-q-service.js index d3a52490..593e59f7 100644 --- a/storeQuestionService/store-q-service.js +++ b/storeQuestionService/store-q-service.js @@ -40,7 +40,7 @@ app.post('/history/question', async (req, res) => { await newQuestion.save(); res.json(newQuestion); } catch (error) { - res.status(400).json({ error: error.message }); + res.status(400).json({ error: error.message || 'An error occurred'}); } }); @@ -69,7 +69,7 @@ app.post('/history/questions', async (req, res) => { res.json(newQuestions); } catch (error) { - res.status(400).json({ error: error.message }); + res.status(400).json({ error: error.message || 'An error occurred'}); } }); @@ -88,7 +88,7 @@ app.get('/history/questions', async (req, res) => { respuestas_incorrectas: ['Segovia','León','Valladolid'] }]);*/ } catch (error) { - res.status(500).json({ error: error.message }); + res.status(500).json({ error: error.message || 'An error occurred'}); } }); From cc0bb05dacaa14d1d39f6ff27ec6d5275e5c8e6d Mon Sep 17 00:00:00 2001 From: Marco Quintana Date: Thu, 4 Apr 2024 19:42:15 +0200 Subject: [PATCH 2/5] added testing jobs to release --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbc3e1fe..d6a15261 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,11 +17,14 @@ jobs: - run: npm --prefix gatewayservice ci - run: npm --prefix questionsservice/questiongeneratorservice ci - run: npm --prefix storeQuestionService ci + - run: npm --prefix userStatsService ci - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage + - run: npm --prefix storeQuestionService test -- --coverage + - run: npm --prefix userStatsService test -- --coverage - name: Analyze with SonarCloud uses: sonarsource/sonarcloud-github-action@master env: From d14a4fcdcd82279b74b9f33f2067c193f26d255c Mon Sep 17 00:00:00 2001 From: Marco Quintana Date: Thu, 4 Apr 2024 19:55:32 +0200 Subject: [PATCH 3/5] Attempt to fix last sonar issue --- webapp/src/components/Button.jsx | 5 ++--- webapp/src/components/FirstGame.css | 7 ------- webapp/src/index.css | 5 +++++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/webapp/src/components/Button.jsx b/webapp/src/components/Button.jsx index 568bbf20..d57b79fa 100644 --- a/webapp/src/components/Button.jsx +++ b/webapp/src/components/Button.jsx @@ -11,7 +11,7 @@ function Button(props){ return (
- +
); } diff --git a/webapp/src/components/FirstGame.css b/webapp/src/components/FirstGame.css index 600670b8..8ab4704e 100644 --- a/webapp/src/components/FirstGame.css +++ b/webapp/src/components/FirstGame.css @@ -1,10 +1,3 @@ -button { - font-size: 20px; - width: 200px; - height: 50px; - justify-content: center; -} - .questionStructure{ border-radius: 1em; border-width: 1px; diff --git a/webapp/src/index.css b/webapp/src/index.css index 8f1627bb..fa8ef691 100644 --- a/webapp/src/index.css +++ b/webapp/src/index.css @@ -149,6 +149,11 @@ code { text-align: center; } +button.inner { + border: none; + font-size: inherit; +} + a{ text-decoration: underline; cursor: pointer; From 4bf777534d31bd51bec7e5c2c1e67a885b1b6a4c Mon Sep 17 00:00:00 2001 From: Marco Quintana Date: Thu, 4 Apr 2024 21:57:14 +0200 Subject: [PATCH 4/5] style bugs fixed --- webapp/public/index.html | 3 ++- webapp/src/index.css | 13 ++++++++++++- webapp/src/userStats/css/Game.css | 6 ++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/webapp/public/index.html b/webapp/public/index.html index aa069f27..0313f098 100644 --- a/webapp/public/index.html +++ b/webapp/public/index.html @@ -4,7 +4,8 @@ - + + Date: Fri, 5 Apr 2024 09:24:58 +0200 Subject: [PATCH 5/5] minor fix Co-authored-by: Abel <114153419+AbelMH1@users.noreply.github.com> --- gatewayservice/gateway-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 1c77619a..a8d4ce31 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -21,7 +21,7 @@ const metricsMiddleware = promBundle({includeMethod: true}); function catchAction(error, res) { if ('response' in error && 'status' in error.response && 'data' in error.response && 'error' in error.response.data) res.status(error.response.status).json({ error: error.response.data.error }); - else if('response' in error && 'status'){ + else if('response' in error && 'status' in error.response){ res.status(error.response.status).json({ error: 'Unknown error' }); } else { console.log("Unknown error: " + error);