Skip to content

Commit

Permalink
Merge pull request #415 from Arquisoft/laura
Browse files Browse the repository at this point in the history
cambios micro gateway aumento coverage + algunas issues de sonar menores
  • Loading branch information
uo277310 authored Apr 26, 2024
2 parents 001546f + f6234ef commit 832457f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 105 deletions.
115 changes: 13 additions & 102 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ app.post('/adduser', async (req, res) => {
const userResponse = await axios.post(userServiceUrl+'/adduser', req.body);
res.json(userResponse.data);
} catch (error) {
if(error.response==undefined){
// usuario ya registrado
res.status(500).json( { error : "That username is already registered"} );
}else{
res.status(error.response.status).json({ error: error.response.data.error });
}
res.status(error.response.status).json({ error: error.response.data.error });
}
});

Expand All @@ -67,11 +62,7 @@ app.post('/addRecord', async(req, res) => {
const recordResponse = await axios.post(recordServiceUrl+'/addRecord', req.body);
res.json(recordResponse.data);
}catch (error){
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -81,11 +72,7 @@ app.post('/addQuestion', async (req, res) => {
const questionResponse = await axios.post(`${questionServiceUrl}/addQuestion`, req.body);
res.json(questionResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -95,11 +82,7 @@ app.get('/getAllUsers', async (req, res) => {
const usersResponse = await axios.get(`${userServiceUrl}/getAllUsers`);
res.json(usersResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
})

Expand All @@ -112,11 +95,7 @@ app.post('/addGeneratedQuestion', async (req, res) => {
const genQuestResponse = await axios.post(genQuestServiceUrl+'/addGeneratedQuestion', req.body);
res.json(genQuestResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
})

Expand All @@ -127,11 +106,7 @@ app.get('/getAllGeneratedQuestions', async (req, res) => {

res.json(genQuestResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
})

Expand All @@ -143,11 +118,7 @@ app.get('/getRecords/:userId', async (req, res) => {
const recordsResponse = await axios.get(`${recordServiceUrl}/getRecords/${userId}`);
res.json(recordsResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -157,11 +128,7 @@ app.get('/getFullQuestion', async (req, res) => {
const questionResponse = await axios.get(`${questionServiceUrl}/getFullQuestion`);
res.json(questionResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -170,11 +137,7 @@ app.get('/actRanking', async (req, res) => {
const rankingResponse = await axios.get(`${recordServiceUrl}/actRanking`);
res.json(rankingResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -186,11 +149,7 @@ app.post('/createUserRank', async (req, res) => {
const rankingResponse = await axios.post(`${rankingServiceUrl}/createUserRank`, req.body);
res.json(rankingResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -201,11 +160,7 @@ app.get('/obtainRank', async (req, res) => {
const rankingsResponse = await axios.get(`${rankingServiceUrl}/obtainRank`);
res.json(rankingsResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -215,11 +170,7 @@ app.post('/updateRanking', async (req, res) => {
const rankingResponse = await axios.post(`${rankingServiceUrl}/updateRanking`, req.body);
res.json(rankingResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -229,11 +180,7 @@ app.post('/updateAllRanking', async (req, res) => {
const rankingResponse = await axios.post(`${rankingServiceUrl}/updateAllRanking`, req.body);
res.json(rankingResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -246,11 +193,7 @@ app.post('/addOrUpdateQuestionGenerator', async (req, res) => {
const questionGeneratorResponse = await axios.post(`${questiongeneratorserviceUrl}/addOrUpdateQuestionGenerator`, req.body);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -260,24 +203,16 @@ app.get('/getRandomQuestionSports', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getRandomQuestionDeporte`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

app.get('/getRandomQuestionImportantDates', async (req, res) => {
try {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getRandomQuestionAnio`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
} catch (error) {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -286,11 +221,7 @@ app.get('/getRandomQuestionMusic', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getRandomQuestionMusica`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -299,11 +230,7 @@ app.get('/getRandomQuestionLiterature', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getRandomQuestionLibro`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
res.status(500).json({ error: 'Error interno del servidor' });
}
});

Expand All @@ -312,11 +239,7 @@ app.get('/getRandomQuestionCountries', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getRandomQuestionPaisYGeo`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -327,11 +250,7 @@ app.get('/getAllQuestionGenerator', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/getAllQuestionGenerator`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -341,11 +260,7 @@ app.get('/countQuestionGenerator', async (req, res) => {
const questionGeneratorResponse = await axios.get(`${questiongeneratorserviceUrl}/countQuestionGenerator`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand All @@ -355,11 +270,7 @@ app.delete('/deleteFirstQuestionGenerator', async (req, res) => {
const questionGeneratorResponse = await axios.delete(`${questiongeneratorserviceUrl}/deleteFirstQuestionGenerator`);
res.json(questionGeneratorResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Game.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import Game from './Game';

describe('Game component', () => {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/GameSettings.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, waitFor, fireEvent, queryByAltText } from '@testing-library/react';
import { render, waitFor, fireEvent } from '@testing-library/react';
import GameSettings from './GameSettings';

describe('GameSettings', () => {
Expand Down
1 change: 0 additions & 1 deletion webapp/src/components/GeneratedQuestionsList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import React, { useState, useEffect } from 'react';
import axios from 'axios';
//import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';

const GeneratedQuestionsList = () => {

Expand Down

0 comments on commit 832457f

Please sign in to comment.