Skip to content

Commit

Permalink
Conectando el servicio retrieve-service al gateway y a la aplicacion
Browse files Browse the repository at this point in the history
  • Loading branch information
baraganio committed Mar 27, 2024
1 parent 8a5dde3 commit 458a4e5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
15 changes: 12 additions & 3 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 creationServiceUrl = process.env.CREATION_SERVICE_URL || 'http://localhost:8005';
const retrieveServiceUrl = process.env.RETRIEVE_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -43,10 +44,18 @@ app.post('/adduser', async (req, res) => {
app.post('/createquestion', async (req, res) => {
try {
// Create a petition to the URL (le llegará a creation-service.js) with the option /createquestion and the req.body params
console.log("salgo de gateway hacia creation");
const questionResponse = await axios.post(creationServiceUrl+'/createquestion', req.body);
console.log("vengo de creation y estoy en gateway");
console.log(questionResponse.status);
// Return a json response with what we obtained on the petition
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.post('/getquestionshistory', async (req, res) => {
try {
// Create a petition to the URL (le llegará a retrieve-service.js) with the option /getgeneratedquestions and the req.body params
const questionResponse = await axios.post(retrieveServiceUrl+'/getquestionshistory', req.body);
// Return a json response with what we obtained on the petition
res.json(questionResponse.data);
} catch (error) {
Expand Down
File renamed without changes.
41 changes: 3 additions & 38 deletions questions/retrieveservice/retrieve-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,9 @@ mongoose.connect(mongoUri);



app.post('/retrievequestion', async (req, res) => {
/*const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(queries[randomQuerySelector])}&format=json`;
try {
// Makes the petition to the url
const response = await fetch(apiUrl, {
headers: {
'Accept': 'application/json'
}
});
// Check if everything was good on the petition
if (!response.ok) {
console.error('Error al realizar la consulta a Wikidata:', response.statusText);
return;
}
// Parse the response
const data = await response.json();
// Send the parsed response to be selected
getQuestionInfo(data.results.bindings);
// Declare what will be return
solution = {
responseQuestionObject : questionObject,
responseCorrectOption : correctOption,
responseAnswerOptions : answerOptions
};
saveQuestion();
// Return the resoult with a 200 status
res.status(200).json(solution);
} catch (error) {
console.error('Error al realizar la consulta:', error);
res.status(500).json({ error: 'Internal Server Error' });
}*/
app.post('/getquestionshistory', async (req, res) => {

res.status(200).json('todo bien');
});

const server = app.listen(port, () => {
Expand Down
28 changes: 25 additions & 3 deletions webapp/src/components/HistoricalData.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Typography} from '@mui/material';
import axios from 'axios';
import { Container, Typography, Button} from '@mui/material';

const HistoricalData = () => {
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

const handleShowHistory = async () => {
try{
// It makes a petition to the api and store the response
const response = await axios.post(`${apiEndpoint}/getquestionshistory`, { });
console.log(response);
}catch (error){
console.error('Error:', error);
}
}

return (
<Typography variant="h4" gutterBottom>

<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<div>
<Typography variant="h4" gutterBottom>
Pagina del HistoricalData
</Typography>
</Typography>

<Button variant="contained" color="primary" onClick={handleShowHistory}>
Histórico de partidas
</Button>
</div>
</Container>

);
};

Expand Down

0 comments on commit 458a4e5

Please sign in to comment.