diff --git a/docker-compose.yml b/docker-compose.yml index d8af9638..04eca969 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_URI: mongodb://mongodb:27017/questiondb retrieveservice: container_name: retrieveservice-${teamname:-defaultASW} @@ -37,7 +37,7 @@ services: networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_URI: mongodb://mongodb:27017/questiondb authservice: container_name: authservice-${teamname:-defaultASW} diff --git a/questions/creationservice/creation-model.js b/questions/creationservice/creation-model.js index bc9e641e..378bf26d 100644 --- a/questions/creationservice/creation-model.js +++ b/questions/creationservice/creation-model.js @@ -2,11 +2,26 @@ const mongoose = require('mongoose'); // Crea la base de datos con las columnas especificadas const questionSchema = new mongoose.Schema({ - question: String, - correctAnswer: String, - incorrectAnswer1: String, - incorrectAnswer2: String, - incorrectAnswer3: String + question: { + type: String, + required: true, + }, + correctAnswer: { + type: String, + required: true, + }, + incorrectAnswer1: { + type: String, + required: true, + }, + incorrectAnswer2: { + type: String, + required: true, + }, + incorrectAnswer3: { + type: String, + required: true, + }, }); const Question = mongoose.model('Question', questionSchema); diff --git a/questions/retrieveservice/retrieve-service.js b/questions/retrieveservice/retrieve-service.js index 7d761233..3ece0bc3 100644 --- a/questions/retrieveservice/retrieve-service.js +++ b/questions/retrieveservice/retrieve-service.js @@ -1,6 +1,6 @@ const express = require('express'); const mongoose = require('mongoose'); -const fetch = require('node-fetch'); +const Question = require('./questionshistory-model') const app = express(); const port = 8004; @@ -11,10 +11,15 @@ const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiond mongoose.connect(mongoUri); - app.post('/getquestionshistory', async (req, res) => { + const questions = await Question.find({}); - res.status(200).json('todo bien'); + var solution = []; + questions.forEach(row => { + solution.push([row.question,row.correctAnswer,row.incorrectAnswer1,row.incorrectAnswer2,row.incorrectAnswer3]); + }); + + res.status(200).json(solution); }); const server = app.listen(port, () => { diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 99951e66..ccbda51e 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -109,7 +109,7 @@ const Game = () => { Saber y Ganar Juego - Pregunta {questionCounter}: ¿Cuál es la capital de {questionObject}? + Pregunta {questionCounter}: {questionObject}
{answerOptions.map((option, index) => ( diff --git a/webapp/src/components/HistoricalData.js b/webapp/src/components/HistoricalData.js index aa5f588d..904836c4 100644 --- a/webapp/src/components/HistoricalData.js +++ b/webapp/src/components/HistoricalData.js @@ -1,31 +1,64 @@ import axios from 'axios'; +import React, { useState} from 'react'; +import { useNavigate} from 'react-router-dom'; import { Container, Typography, Button} from '@mui/material'; const HistoricalData = () => { + const navigate = useNavigate(); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; + const [questionsHistory, setQuestionsHistory] = useState([]); + 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); + setQuestionsHistory(response.data); }catch (error){ console.error('Error:', error); } } + const handlePreviousPage = async () => { + let path= '/MainPage'; + navigate(path); + } + return ( +
- - Pagina del HistoricalData - +
+
+ + + + + + + + + + + + {questionsHistory.map((row, rowIndex) => ( + + {row.map((cell, cellIndex) => ( + + ))} + + ))} + +
PreguntaOpción correctaOpción incorrecta 1Opción incorrecta 2Opción incorrecta 3
{cell}
+
);