diff --git a/docker-compose.yml b/docker-compose.yml index 67c6aff6..2caf2f81 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: networks: - mynetwork - creationervice: + creationservice: container_name: creationservice-${teamname:-defaultASW} image: ghcr.io/arquisoft/wiq_es2b/creationservice:latest profiles: ["dev", "prod"] @@ -62,6 +62,7 @@ services: - mongodb - userservice - authservice + - creationservice ports: - "8000:8000" networks: @@ -69,6 +70,7 @@ services: environment: AUTH_SERVICE_URL: http://authservice:8002 USER_SERVICE_URL: http://userservice:8001 + CREATION_SERVICE_URL: http://creationservice:8005 webapp: container_name: webapp-${teamname:-defaultASW} diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 50ce1083..945d2a97 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -48,7 +48,6 @@ app.post('/adduser', async (req, res) => { app.post('/createquestion', async (req, res) => { try { - console.log('eyou'); // Crea una peticion a la url (le llegará a creation-service.js) con la opcion /login // y los parametros req.body const questionResponse = await axios.post(creationServiceUrl+'/createquestion', req.body); diff --git a/questions/creationservice/creation-service.js b/questions/creationservice/creation-service.js index 3b1c384d..49eb5d59 100644 --- a/questions/creationservice/creation-service.js +++ b/questions/creationservice/creation-service.js @@ -18,23 +18,26 @@ app.post('/createquestion', async (req, res) => { // TODO LO COMENTADO ES UN INTENTO DE HACER LAS QUERIES // PERO COMO SALTA UN ERROR ANTES, NO SE PRUEBA CON ELLAS - /*const sparqlQuery = 'SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel WHERE { ?country wdt:P31 wd:Q6256. ?country wdt:P36 ?capital. SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}'; + const sparqlQuery = 'SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel WHERE { ?country wdt:P31 wd:Q6256. ?country wdt:P36 ?capital. SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es".}}'; const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(sparqlQuery)}`; - const headers = { "Accept": "application/json" };*/ + const headers = { "Accept": "application/json" }; try { - - //const respuestaWikidata = await fetch(apiUrl, {headers}); - //if (respuestaWikidata.ok) { - //const data = await respuestaWikidata.json();//obtengo los datos en json - //const numEles = data.results.bindings.length; - //const index = Math.floor(Math.random() * numEles);//index al azar - //result = data.results.bindings[index]; + const respuestaWikidata = await fetch(apiUrl, {headers}); + console.log(respuestaWikidata); + if (respuestaWikidata.ok) { + console.log('Entro al if'); + const data = await respuestaWikidata.json();//obtengo los datos en json + const numEles = data.results.bindings.length; + const index = Math.floor(Math.random() * numEles);//index al azar - console.log(req); + res = data.results.bindings[index]; // Hardcodeo el resultado para hacer pruebas - res.json({ token: 'asdf'}); - //} + // res.json({ token: 'asdf'}); + }else{ + console.log('no entra al if'); + console.log('la peticion tiene un status:' ,respuestaWikidata.status); + } } catch (error) { res.status(500).json({ error: 'Internal Server Error' }); } diff --git a/webapp/src/App.js b/webapp/src/App.js index 616b183f..a3090c90 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -3,7 +3,8 @@ import React, { useState } from 'react'; import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; // Cambiado de Switch a Routes import AddUser from './components/AddUser'; import Login from './components/Login'; -import Juego from './components/Juego'; +import Game from './components/Game'; +import HistoricalData from './components/HistoricalData'; import CssBaseline from '@mui/material/CssBaseline'; import Container from '@mui/material/Container'; import Typography from '@mui/material/Typography'; @@ -26,7 +27,8 @@ function App() { - } /> + } /> + } /> {showLogin ? : } diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 1434b644..b8a17de7 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -1,14 +1,16 @@ import React, { useState } from 'react'; import axios from 'axios'; -import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +import { Container, Typography, TextField, Button, Snackbar, Paper } from '@mui/material'; const Game = () => { + const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const [askForQuestion, setAskForQuestion] = useState(false); const [pais, setpais] = useState(''); - const [capital, setcapital] = useState(''); - - const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; + const [capitalCorrecta, setcapital] = useState(''); + const [capitalIcnorrecta1, setcapitalIcnorrecta1] = useState(''); + const [capitalIcnorrecta2, setcapitalIcnorrecta2] = useState(''); + const [capitalIcnorrecta3, setcapitalIcnorrecta3] = useState(''); // Esta es la llamada al servicio de generar las preguntas const handleShowQuestion = async () => { @@ -36,35 +38,51 @@ const Game = () => { if (respuestaWikidata.ok) { const data = await respuestaWikidata.json(); const numEles = data.results.bindings.length; - const index = Math.floor(Math.random() * numEles); - const result = data.results.bindings[index]; + const indexCapCorre = Math.floor(Math.random() * numEles); + const result = data.results.bindings[indexCapCorre]; setpais(result.countryLabel.value); setcapital(result.capitalLabel.value); + + const indexCapIncorre1 = Math.floor(Math.random() * numEles); + const indexCapIncorre2 = Math.floor(Math.random() * numEles); + const indexCapIncorre3 = Math.floor(Math.random() * numEles); + setcapitalIcnorrecta1(data.results.bindings[indexCapIncorre1].capitalLabel.value); + setcapitalIcnorrecta2(data.results.bindings[indexCapIncorre2].capitalLabel.value); + setcapitalIcnorrecta3(data.results.bindings[indexCapIncorre3].capitalLabel.value); } else { console.error("Error al realizar la consulta en Wikidata. Estado de respuesta:", respuestaWikidata.status); } } return ( - - - Esta sería la pagina del juego - + + + + Saber y Ganar Juego + + + Pregunta: ¿Cuál es la capital de {pais}? + + {/* Botones de opción */} + + + + + - {askForQuestion ? ( - - Pais {pais} capital {capital} - - ) : ( - - Dale al boton - - ) } ); }; diff --git a/webapp/src/components/HistoricalData.js b/webapp/src/components/HistoricalData.js index ffaccebb..c96207ca 100644 --- a/webapp/src/components/HistoricalData.js +++ b/webapp/src/components/HistoricalData.js @@ -5,9 +5,9 @@ import { Container, Typography, TextField, Button, Snackbar } from '@mui/materia const HistoricalData = () => { return ( -
-

Esta sería la pagina del historico de partidas

-
+ + Pagina del HistoricalData + ); }; diff --git a/webapp/src/components/Juego.js b/webapp/src/components/Juego.js deleted file mode 100644 index b9a524a4..00000000 --- a/webapp/src/components/Juego.js +++ /dev/null @@ -1,33 +0,0 @@ -// Juego.js -import React from 'react'; -import { Button, Typography, Container, Paper } from '@mui/material'; - -function Juego() { - return ( - - - - Saber y Ganar Juego - - - Pregunta: ¿Cuál es la capital de Francia? - - {/* Botones de opción */} - - - - - - - ); -} - -export default Juego; diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index 61a35cbc..9b63d84d 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -2,9 +2,8 @@ import React, { useState } from 'react'; import axios from 'axios'; import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; -import Game from './Game'; +import { useNavigate } from 'react-router-dom'; import HistoricalData from './HistoricalData'; -import App from '../App'; const Login = () => { const [username, setUsername] = useState(''); @@ -15,8 +14,8 @@ const Login = () => { const [openSnackbar, setOpenSnackbar] = useState(false); // Declara las variables (izquierda) y el metodo que la modifica (derecha). Se inicializa a false (useState) - const [showGame, setShowGame] = useState(false); const [showHistoricalData, setShowHistoricaData] = useState(false); + const navigate = useNavigate(); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -41,11 +40,13 @@ const Login = () => { }; const handleShowGame = () => { - setShowGame(true); + let path= '/Game'; + navigate(path); }; const handleShowHistoricalData = () => { - setShowHistoricaData(true); + let path= '/HistoricalData'; + navigate(path); }; return ( @@ -53,13 +54,7 @@ const Login = () => { {/* Los operadores logicos funcionan de la manera: condicion ? (lo que se hace si se cumple) : (lo que se hace si no se cumple) */} {loginSuccess ? ( - showGame || showHistoricalData ? ( - showGame ? ( - - ):( - - ) - ) : ( +
Hello {username}! @@ -76,7 +71,7 @@ const Login = () => { Historico de partidas de jugador
- ) + ) : (