From f8c749db81bfb7f9d97ccabebb4acecda255c96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz=20Cancillo?= Date: Thu, 7 Mar 2024 20:37:38 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Eliminado=20enlace=20crear/iniciar=20sesi?= =?UTF-8?q?=C3=B3n=20usuario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/App.js | 31 ++++++++++++++++++++----------- webapp/src/components/Login.js | 5 +++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/webapp/src/App.js b/webapp/src/App.js index 1324a1b8..47f597f2 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -8,6 +8,11 @@ import Link from '@mui/material/Link'; function App() { const [showLogin, setShowLogin] = useState(true); + const [isLogged, setLogged] = useState(false); + + const handleIsLogged = () => { + setLogged(true); + }; const handleToggleView = () => { setShowLogin(!showLogin); @@ -19,18 +24,22 @@ function App() { Welcome to wiq_6B - {showLogin ? : } - - {showLogin ? ( - - Don't have an account? Register here. - + {showLogin ? : } + {!isLogged ? ( + {showLogin ? ( + + Don't have an account? Register here. + + ) : ( + + Already have an account? Login here. + + )} + ) : ( - - Already have an account? Login here. - - )} - + <> + ) } + ); } diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index 386d87ee..3f89c273 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -9,7 +9,7 @@ import UsersList from './UsersList'; //import Link from '@mui/material/Link'; -const Login = () => { +const Login = ({setLogged}) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); @@ -38,6 +38,7 @@ const Login = () => { }; const handleShowGame = () => { + setLogged(); setShowGame(true); }; @@ -57,7 +58,7 @@ const Login = () => { showGame ? ( < Game/> - ) : + ) : showUsersList?( < UsersList/> From 67900cf655898e69b917545f514d0b6ad80e45ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz=20Cancillo?= Date: Thu, 7 Mar 2024 20:54:27 +0100 Subject: [PATCH 2/3] =?UTF-8?q?A=C3=B1adido=20redireccionamiento=20a=20"/a?= =?UTF-8?q?ddRecord"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/gateway-service.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 3600af67..4746c3e6 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -42,6 +42,14 @@ app.post('/adduser', async (req, res) => { } }); +app.post('/addRecord', async(req, res) => { + try{ + const recordResponse = await axios.post(questionServiceUrl+'/addRecord', req.body); + }catch (error){ + res.status(error.response.status).json({ error: error.response.data.error }); + } +}); + app.post('/getQuestionBody', async (req, res) => { try { // Forward the add user request to the user service From 65349e46694532839e99b48cf975fe4c12610c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz=20Cancillo?= Date: Fri, 8 Mar 2024 01:12:43 +0100 Subject: [PATCH 3/3] Finalizado registro de jugadas --- gatewayservice/gateway-service.js | 3 +- questions/recordservice/record-service.js | 2 +- webapp/src/components/Game.js | 36 +++++++++++++++++++++-- webapp/src/components/Login.js | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 4746c3e6..710e1743 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -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 questionServiceUrl = process.env.QUES_SERVICE_URL || 'http://localhost:8005'; +const recordServiceUrl = process.env.REC_SERVICE_URL || 'http://localhost:8006'; app.use(cors()); app.use(express.json()); @@ -44,7 +45,7 @@ app.post('/adduser', async (req, res) => { app.post('/addRecord', async(req, res) => { try{ - const recordResponse = await axios.post(questionServiceUrl+'/addRecord', req.body); + const recordResponse = await axios.post(recordServiceUrl+'/addRecord', req.body); }catch (error){ res.status(error.response.status).json({ error: error.response.data.error }); } diff --git a/questions/recordservice/record-service.js b/questions/recordservice/record-service.js index ba800bc8..024aa8b6 100644 --- a/questions/recordservice/record-service.js +++ b/questions/recordservice/record-service.js @@ -36,7 +36,7 @@ app.post('/addRecord', async (req, res) => { correctQuestions: req.body.correctQuestions, failedQuestions: req.body.failedQuestions }); - newRecord.save(); + await newRecord.save(); res.json(newRecord); } catch (error) { diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index d92c6fb1..d1f54ed3 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -7,13 +7,16 @@ import { Container, Typography, TextField, Button, Snackbar } from '@mui/materia import Link from '@mui/material/Link'; -const Game = () => { +const Game = ({username}) => { const [questionBody, setQuestionBody] = useState(''); const [informacionWikidata, setInformacionWikidata] = useState(''); const [respuestaCorrecta, setRespuestaCorrecta] = useState(''); const [respuestasFalsas, setRespuestasFalsas] = useState([]); const [numberClics, setNumberClics] = useState(1); const [timer, setTimer] = useState(0); + const [correctQuestions, setCorrectQuestions] = useState(0); + const [error, setError] = useState(''); + const [finish, setFinish] = useState(false); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -96,6 +99,11 @@ const Game = () => { fetchData(); }, [obtenerPreguntaAleatoria]); + const handleButtonClickCorrecta = () => { + setCorrectQuestions(correctQuestions+1); + handleButtonClick(); + }; + const handleButtonClick = () => { setNumberClics(numberClics + 1); obtenerPreguntaAleatoria(); @@ -109,10 +117,32 @@ const Game = () => { return `${minsRStr}:${secsRStr}`; }; + useEffect(() => { + const addRecord = async () => { + try { + const response = await axios.post(`${apiEndpoint}/addRecord`, { + userId: username, + date: new Date(), + time: timer, + money: (25*correctQuestions), + correctQuestions: correctQuestions, + failedQuestions: (10-correctQuestions) + }); + } catch (error) { + setError(error.response.data.error); + } + }; + + if((numberClics>10 || timer>180) && !finish){ + addRecord(); + setFinish(true); + } + }, [numberClics, timer]); + return (
{numberClics > 10 || timer > 180 ? ( -

Fin

+

Fin de la partida

) : ( <> @@ -125,7 +155,7 @@ const Game = () => { {questionBody} {informacionWikidata} - diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index 3f89c273..5fa975d9 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -57,7 +57,7 @@ const Login = ({setLogged}) => { showGame ? ( - < Game/> + < Game username={username}> ) : showUsersList?(