From 2b5b329a46a15b2a048102263d5c16975f0d21de Mon Sep 17 00:00:00 2001 From: bidof Date: Mon, 11 Mar 2024 21:50:12 +0100 Subject: [PATCH 1/8] agregar nueva itnerfaz --- package-lock.json | 187 +++++++++++++++++++++++++++++ package.json | 1 + webapp/src/components/game/Game.js | 53 ++++---- 3 files changed, 210 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2668a58..d70a679 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "@mui/system": "^5.15.12", "bootstrap": "^5.3.3", "cron": "^3.1.6", "dotenv": "^16.4.5", @@ -25,6 +26,179 @@ "node": ">=6.9.0" } }, + "node_modules/@emotion/cache": { + "version": "11.11.0", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.11.0.tgz", + "integrity": "sha512-P34z9ssTCBi3e9EI1ZsWpNHcfY1r09ZO0rZbRO2ob3ZQMnFI35jB536qoXbkdesr5EUhYi22anuEJuyxifaqAQ==", + "dependencies": { + "@emotion/memoize": "^0.8.1", + "@emotion/sheet": "^1.2.2", + "@emotion/utils": "^1.2.1", + "@emotion/weak-memoize": "^0.3.1", + "stylis": "4.2.0" + } + }, + "node_modules/@emotion/memoize": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.8.1.tgz", + "integrity": "sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==" + }, + "node_modules/@emotion/sheet": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.2.2.tgz", + "integrity": "sha512-0QBtGvaqtWi+nx6doRwDdBIzhNdZrXUppvTM4dtZZWEGTXL/XE/yJxLMGlDT1Gt+UHH5IX1n+jkXyytE/av7OA==" + }, + "node_modules/@emotion/utils": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.2.1.tgz", + "integrity": "sha512-Y2tGf3I+XVnajdItskUCn6LX+VUDmP6lTL4fcqsXAv43dnlbZiuW4MWQW38rW/BVWSE7Q/7+XQocmpnRYILUmg==" + }, + "node_modules/@emotion/weak-memoize": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.3.1.tgz", + "integrity": "sha512-EsBwpc7hBUJWAsNPBmJy4hxWx12v6bshQsldrVmjxJoc3isbxhOrF2IcCpaXxfvq03NwkI7sbsOLXbYuqF/8Ww==" + }, + "node_modules/@mui/private-theming": { + "version": "5.15.12", + "resolved": "https://registry.npmjs.org/@mui/private-theming/-/private-theming-5.15.12.tgz", + "integrity": "sha512-cqoSo9sgA5HE+8vZClbLrq9EkyOnYysooepi5eKaKvJ41lReT2c5wOZAeDDM1+xknrMDos+0mT2zr3sZmUiRRA==", + "dependencies": { + "@babel/runtime": "^7.23.9", + "@mui/utils": "^5.15.12", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/styled-engine": { + "version": "5.15.11", + "resolved": "https://registry.npmjs.org/@mui/styled-engine/-/styled-engine-5.15.11.tgz", + "integrity": "sha512-So21AhAngqo07ces4S/JpX5UaMU2RHXpEA6hNzI6IQjd/1usMPxpgK8wkGgTe3JKmC2KDmH8cvoycq5H3Ii7/w==", + "dependencies": { + "@babel/runtime": "^7.23.9", + "@emotion/cache": "^11.11.0", + "csstype": "^3.1.3", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@emotion/react": "^11.4.1", + "@emotion/styled": "^11.3.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + } + } + }, + "node_modules/@mui/system": { + "version": "5.15.12", + "resolved": "https://registry.npmjs.org/@mui/system/-/system-5.15.12.tgz", + "integrity": "sha512-/pq+GO6yN3X7r3hAwFTrzkAh7K1bTF5r8IzS79B9eyKJg7v6B/t4/zZYMR6OT9qEPtwf6rYN2Utg1e6Z7F1OgQ==", + "dependencies": { + "@babel/runtime": "^7.23.9", + "@mui/private-theming": "^5.15.12", + "@mui/styled-engine": "^5.15.11", + "@mui/types": "^7.2.13", + "@mui/utils": "^5.15.12", + "clsx": "^2.1.0", + "csstype": "^3.1.3", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@emotion/react": "^11.5.0", + "@emotion/styled": "^11.3.0", + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/types": { + "version": "7.2.13", + "resolved": "https://registry.npmjs.org/@mui/types/-/types-7.2.13.tgz", + "integrity": "sha512-qP9OgacN62s+l8rdDhSFRe05HWtLLJ5TGclC9I1+tQngbssu0m2dmFZs+Px53AcOs9fD7TbYd4gc9AXzVqO/+g==", + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/utils": { + "version": "5.15.12", + "resolved": "https://registry.npmjs.org/@mui/utils/-/utils-5.15.12.tgz", + "integrity": "sha512-8SDGCnO2DY9Yy+5bGzu00NZowSDtuyHP4H8gunhHGQoIlhlY2Z3w64wBzAOLpYw/ZhJNzksDTnS/i8qdJvxuow==", + "dependencies": { + "@babel/runtime": "^7.23.9", + "@types/prop-types": "^15.7.11", + "prop-types": "^15.8.1", + "react-is": "^18.2.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "peerDependencies": { + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/utils/node_modules/react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + }, "node_modules/@popperjs/core": { "version": "2.11.8", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", @@ -164,6 +338,14 @@ "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" }, + "node_modules/clsx": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.0.tgz", + "integrity": "sha512-m3iNNWpd9rl3jvvcBnu70ylMdrXt8Vlq4HYadnU5fwcOtvkSQWPmj7amUcDT2qYI7risszBjI5AUIUox9D16pg==", + "engines": { + "node": ">=6" + } + }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -541,6 +723,11 @@ "safe-buffer": "~5.1.0" } }, + "node_modules/stylis": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.2.0.tgz", + "integrity": "sha512-Orov6g6BB1sDfYgzWfTHDOxamtX1bE/zo104Dh9e6fqJ3PooipYyfJ0pUmrZO2wAvO8YbEyeFrkV91XTsGMSrw==" + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", diff --git a/package.json b/package.json index c633e34..2d60e0d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "dependencies": { + "@mui/system": "^5.15.12", "bootstrap": "^5.3.3", "cron": "^3.1.6", "dotenv": "^16.4.5", diff --git a/webapp/src/components/game/Game.js b/webapp/src/components/game/Game.js index 3b19519..e83919a 100644 --- a/webapp/src/components/game/Game.js +++ b/webapp/src/components/game/Game.js @@ -1,23 +1,24 @@ // Importa React, useState para manejar el estado, axios para hacer solicitudes HTTP, y componentes de Material UI para la interfaz. import React, { useState } from 'react'; import axios from 'axios'; -import { Container, Typography, Button, Box, Paper, Snackbar } from '@mui/material'; +import { Container, Typography, Button, Snackbar,Grid,Box } from '@mui/material'; import MuiAlert from '@mui/material/Alert'; // Define el endpoint de la API, utilizando una variable de entorno o un valor predeterminado. -const apiEndpoint = process.env.REACT_APP_API_URI || 'http://localhost:8000'; - +const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const Game = () => { + + const buttonColors = ['#ff0000', '#ffff00', '#0000ff', '#00ff00']; + const [question, setQuestion] = useState(''); const [answers, setAnswers] = useState([]); const [loadingMessage, setLoadingMessage] = useState(''); const [snackbarOpen, setSnackbarOpen] = useState(false); const [snackbarMessage, setSnackbarMessage] = useState(''); const [snackbarSeverity, setSnackbarSeverity] = useState('success'); - const [category, setCategory] = useState('');//depuracion - const [type, setType] = useState('');//depuracion + const handleSnackbarClose = (event, reason) => { if (reason === 'clickaway') { @@ -49,8 +50,7 @@ const Game = () => { setQuestion(response.data.question); setAnswers(response.data.answers); setLoadingMessage(''); - setCategory(response.data.questionCategory); // Nueva línea - setType(response.data.questionType); // Nueva línea + } catch (error) { // Manejo básico de errores: imprime el error en la consola. @@ -61,9 +61,9 @@ const Game = () => { // Renderiza el componente. return ( - - Generate Question and Answers - + {question && ( + {question} + )} - - ))} + + ))} + - {/* ... */} - {category && ( - Category: {category} - )} - {type && ( - Type: {type} - )} + {/* ... */} Date: Mon, 11 Mar 2024 22:01:20 +0100 Subject: [PATCH 2/8] mejorar interfaz --- webapp/src/components/game/Game.js | 13 +++++++++---- webapp/src/index.js | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/webapp/src/components/game/Game.js b/webapp/src/components/game/Game.js index e83919a..9864e62 100644 --- a/webapp/src/components/game/Game.js +++ b/webapp/src/components/game/Game.js @@ -10,7 +10,7 @@ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000 const Game = () => { - const buttonColors = ['#ff0000', '#ffff00', '#0000ff', '#00ff00']; + const buttonColors = ['#ff0000', '#00008b', '#0000ff', '#00ff00']; const [question, setQuestion] = useState(''); const [answers, setAnswers] = useState([]); @@ -60,9 +60,9 @@ const Game = () => { // Renderiza el componente. return ( - + {question && ( - {question} + {question} )} + */ } {loadingMessage && ({loadingMessage})} {/* Muestra la pregunta y las respuesta si existen */} diff --git a/webapp/src/components/home/Home.js b/webapp/src/components/home/Home.js new file mode 100644 index 0000000..6bbc3c0 --- /dev/null +++ b/webapp/src/components/home/Home.js @@ -0,0 +1,17 @@ +import React from 'react'; +import Navbar from '../navbar/NavBar'; +import StartButton from '../startbutton/StartButton'; +import Typography from '@mui/material/Typography'; +import Footer from '../footer/Footer'; +const Home = () => { + return ( +
+ + + + +
+ ); +}; + +export default Home; \ No newline at end of file diff --git a/webapp/src/components/home/home.css b/webapp/src/components/home/home.css new file mode 100644 index 0000000..d177342 --- /dev/null +++ b/webapp/src/components/home/home.css @@ -0,0 +1,14 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + } + + code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; + } + \ No newline at end of file diff --git a/webapp/src/index.js b/webapp/src/index.js index 8bc30f4..3ea19f1 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -1,53 +1,16 @@ import React from 'react'; -import ReactDOM from 'react-dom/client'; +import ReactDOM from 'react-dom'; import './index.css'; +import App from './App'; import reportWebVitals from './reportWebVitals'; -import Navbar from './components/navbar/NavBar'; -import AddUser from './components/adduser/AddUser'; -import Login from './components/login/Login'; -import { AuthProvider } from './components/authcontext'; -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; -import CssBaseline from '@mui/material/CssBaseline'; -import Typography from '@mui/material/Typography'; -import StartButton from './components/startbutton/StartButton'; -import Game from './components/game/Game'; -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( +ReactDOM.render( - - - - - - Bienvenidos al curso 2024 de arquitectura de software somos el grupo : - - wiq_es04c - - } /> - } /> - } /> - } /> - - - - - - - - - - - - - - - - + - - + , + document.getElementById('root') ); reportWebVitals(); \ No newline at end of file From 051307dd7f0b554b53757477c82976655550f1a9 Mon Sep 17 00:00:00 2001 From: bidof Date: Mon, 11 Mar 2024 23:50:31 +0100 Subject: [PATCH 7/8] bug que cerraba el microservicio --- questionservice/scheduler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/questionservice/scheduler.js b/questionservice/scheduler.js index 901dcc2..e2ccd4f 100644 --- a/questionservice/scheduler.js +++ b/questionservice/scheduler.js @@ -26,7 +26,8 @@ class Scheduler { cron.schedule('*/30 * * * *', async () => { this.success = false; while (!this.success) { - this.addQuestion(); + //ojo como es asincrono si no lo pones el bucle se sigue ejecutando y petas la pila de javasycrpit y cae el contendor + await this.addQuestion(); } }); } From 953350df78a1fb04a8c042f5da92e3bdee63187d Mon Sep 17 00:00:00 2001 From: bidof Date: Tue, 12 Mar 2024 00:18:40 +0100 Subject: [PATCH 8/8] generacion de preguntas cada x minutos sin bugs --- questionservice/scheduler.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/questionservice/scheduler.js b/questionservice/scheduler.js index e2ccd4f..7bc665f 100644 --- a/questionservice/scheduler.js +++ b/questionservice/scheduler.js @@ -21,14 +21,26 @@ class Scheduler { console.error(error); } } - + start() { - cron.schedule('*/30 * * * *', async () => { + cron.schedule('*/15 * * * *', async () => { + + try { + await this.addQuestion(); + } catch (error) { + console.error('Failed to add question:', error); + // Aquí podrías implementar una lógica para manejar el error, como reintentar después de un tiempo, + // enviar una alerta, etc. + } + + + /* version con errores this.success = false; while (!this.success) { //ojo como es asincrono si no lo pones el bucle se sigue ejecutando y petas la pila de javasycrpit y cae el contendor await this.addQuestion(); } + */ }); } }