Skip to content

Commit

Permalink
Merge pull request #136 from Arquisoft/dev
Browse files Browse the repository at this point in the history
Cambios para versión 0.1
  • Loading branch information
uo285427 authored Mar 14, 2024
2 parents 94d8db9 + f7ac14a commit 32a1ee4
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 47 deletions.
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/userdb?retryWrites=true&w=majority&appName=wiq06b

userservice:
container_name: userservice-${teamname:-wiq_es06b}
Expand All @@ -37,7 +37,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/userdb?retryWrites=true&w=majority&appName=wiq06b

answerservice:
container_name: answerservice-${teamname:-wiq_es06b}
Expand All @@ -51,7 +51,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b

createservice:
container_name: createservice-${teamname:-wiq_es06b}
Expand All @@ -65,7 +65,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b

recordservice:
container_name: recordservice-${teamname:-wiq_es06b}
Expand All @@ -79,7 +79,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/recorddb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/recorddb?retryWrites=true&w=majority&appName=wiq06b

generatedquestservice:
container_name: generatedquestservice-${teamname:-wiq_es06b}
Expand All @@ -89,11 +89,11 @@ services:
depends_on:
- mongodb
ports:
- "8007:8007"
- "8003:8003"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
MONGODB_URI: mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b

gatewayservice:
container_name: gatewayservice-${teamname:-wiq_es06b}
Expand All @@ -118,7 +118,7 @@ services:
ANSW_SERVICE_URL: http://answerservice:8004
QUES_SERVICE_URL: http://createservice:8005
REC_SERVICE_URL: http://recordservice:8006
GEN_SERVICE_URL: http://generatedquestservice:8007
GEN_SERVICE_URL: http://generatedquestservice:8003

webapp:
container_name: webapp-${teamname:-wiq_es06b}
Expand Down
18 changes: 17 additions & 1 deletion gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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';
const genQuestServiceUrl = process.env.GEN_SERVICE_URL || 'http://localhost:8007';
const genQuestServiceUrl = process.env.GEN_SERVICE_URL || 'http://localhost:8003';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -122,6 +122,22 @@ app.get('/getAllGeneratedQuestions', async (req, res) => {
}
})

app.get('/getRecords/:userId', async (req, res) => {
try {

const userId = req.params.userId;

const recordsResponse = await axios.get(`${recordServiceUrl}/getRecords/${userId}`);
res.json(recordsResponse.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error interno del servidor' });
}
}
});


// Start the gateway service
const server = app.listen(port, () => {
Expand Down
2 changes: 1 addition & 1 deletion questions/answerservice/answer-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const port = 8004;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);


Expand Down
2 changes: 1 addition & 1 deletion questions/createservice/create-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const port = 8005;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);


Expand Down
4 changes: 2 additions & 2 deletions questions/generatedquestservice/generatedquest-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const generatedQuest = new mongoose.Schema({

generatedQuestionBody: {
type: String,
required: true,
required: false,
},
correctAnswer: {
type: String,
required: true,
required: false,
},
});

Expand Down
4 changes: 2 additions & 2 deletions questions/generatedquestservice/generatedquest-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const bodyParser = require('body-parser');
const GeneratedQuestion = require('./generatedquest-model');

const app = express();
const port = 8007;
const port = 8003;

// Middleware to parse JSON in request body
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/generatedquestdb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/questiondb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);

// Route for user login
Expand Down
2 changes: 1 addition & 1 deletion questions/recordservice/record-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const port = 8006;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/recorddb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/recorddb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);

// Function to validate required fields in the request body
Expand Down
2 changes: 1 addition & 1 deletion users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const port = 8002;
app.use(express.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/userdb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);

// Function to validate required fields in the request body
Expand Down
2 changes: 1 addition & 1 deletion users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const port = 8001;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
const mongoUri = process.env.MONGODB_URI || 'mongodb+srv://aswuser:aswuser@wiq06b.hsfgpcm.mongodb.net/userdb?retryWrites=true&w=majority&appName=wiq06b';
mongoose.connect(mongoUri);


Expand Down
1 change: 0 additions & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function App() {
<Container component="main" maxWidth="lg" style={{ marginTop: '2rem', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>

<Paper elevation={3} style={{ padding: '2rem', textAlign: 'center', height: '500px', width: '800px', overflow: 'auto' }}>


{showLogin ? <Login setLogged={handleIsLogged}/> : <AddUser />}
{!isLogged ? (<Typography component="div" align="center" sx={{ marginTop: 4 }}>
Expand Down
61 changes: 35 additions & 26 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// src/components/Game.js
import axios from 'axios';
import React, { useState, useEffect, useCallback, useMemo } from 'react';
//import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';
import { Container, Typography, Button, Snackbar } from '@mui/material';


//import Link from '@mui/material/Link';
import { Container, Typography, Button, Snackbar, CircularProgress } from '@mui/material';

const Game = ({username}) => {
const [questionBody, setQuestionBody] = useState('');
Expand All @@ -18,6 +13,7 @@ const Game = ({username}) => {
const [error, setError] = useState('');
const [finish, setFinish] = useState(false);
const [buttons, setButtons] = useState([]);
const [isLoading, setIsLoading] = useState(true); // Nuevo estado para controlar la pantalla de carga

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

Expand Down Expand Up @@ -111,6 +107,7 @@ const Game = ({username}) => {
try{
setNumberClics(numberClics + 1);
await obtenerPreguntaAleatoria();

addGeneratedQuestionBody();
}catch(error)
{
Expand Down Expand Up @@ -150,6 +147,7 @@ const Game = ({username}) => {
useEffect(() => {
const fetchData = async () => {
await obtenerPreguntaAleatoria();
setIsLoading(false); // Cuando se carga la pregunta, se cambia el estado para dejar de mostrar la pantalla de carga
};
fetchData();
}, [obtenerPreguntaAleatoria]);
Expand Down Expand Up @@ -188,28 +186,39 @@ const Game = ({username}) => {
return (
<Container maxWidth="lg">
<div>
{numberClics > 10 || timer > 180 ? (
<p>Fin de la partida</p>
{isLoading ? ( // Mostrar la pantalla de carga si isLoading es verdadero
<div style={{ textAlign: 'center', marginTop: '50px' }}>
<CircularProgress />
<Typography variant="h6" gutterBottom>
Cargando...
</Typography>
</div>
) : (
<>
<Typography component="h1" variant='h5' sx={{ textAlign: 'center' }}>
Pregunta Número {numberClics} :
</Typography>
<Typography component="h2" sx={{ textAlign: 'center', color: (timer > 120 && (timer % 60) % 2 === 0) ? 'red' : 'inherit', fontStyle: 'italic', fontWeight: (timer > 150 && (timer % 60) % 2 === 0) ? 'bold' : 'inherit' }}>
¡Tiempo restante {handleTimeRemaining()}!
</Typography>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
{questionBody} {informacionWikidata}
</Typography>

{ buttons.map((button) => (
<Button variant="contained" color="primary" onClick={button.handler} >
{button.answer}
</Button>
))}

</div>
{numberClics > 10 || timer > 180 ? (
<p>Fin de la partida</p>
) : (
<>
<Typography component="h1" variant='h5' sx={{ textAlign: 'center' }}>
Pregunta Número {numberClics} :
</Typography>
<Typography component="h2" sx={{ textAlign: 'center', color: (timer > 120 && (timer % 60) % 2 === 0) ? 'red' : 'inherit', fontStyle: 'italic', fontWeight: (timer > 150 && (timer % 60) % 2 === 0) ? 'bold' : 'inherit' }}>
¡Tiempo restante {handleTimeRemaining()}!
</Typography>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
{questionBody} {informacionWikidata}
</Typography>

{ buttons.map((button) => (
<Button variant="contained" color="primary" onClick={button.handler} >
{button.answer}
</Button>
))}

</div>
</>
)}
</>
)}
{error && (
Expand Down
32 changes: 30 additions & 2 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Container, Typography, TextField, Button, Snackbar, AppBar, Toolbar } f
import Game from './Game';
import UsersList from './UsersList';
import GeneratedQuestionsList from './GeneratedQuestionsList';
import RecordList from './RecordList';

//import Link from '@mui/material/Link';

Expand All @@ -20,6 +21,7 @@ const Login = ({setLogged}) => {
const [showGame, setShowGame] = useState(false);
const [showUsersList, setShowUsersList] = useState(false);
const [showQuestionList, setShowQuestionList] = useState(false);
const [showRecordList, setShowRecordList] = useState(false);

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

Expand All @@ -32,7 +34,7 @@ const Login = ({setLogged}) => {

setCreatedAt(userCreatedAt);
setLoginSuccess(true);

setLogged();
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
Expand All @@ -43,17 +45,33 @@ const Login = ({setLogged}) => {
setLogged();
setShowGame(true);
setShowUsersList(false);
setShowQuestionList(false);
setShowRecordList(false);
};

const handleShowUsersList = () => {
setLogged();
setShowUsersList(true);
setShowGame(false);
setShowQuestionList(false);
setShowRecordList(false);
};

const handleShowRecordList = () => {
setLogged();
setShowRecordList(true);
setShowGame(false);
setShowUsersList(false);
setShowQuestionList(false);
};


const handleShowQuestionList = () => {
setLogged();
setShowQuestionList(true);
setShowGame(false);
setShowUsersList(false);
setShowRecordList(false);
};
const handleCloseSnackbar = () => {
setOpenSnackbar(false);
Expand All @@ -77,6 +95,11 @@ const Login = ({setLogged}) => {
Historial de Preguntas Generadas
</Button>
)}

<Button color="inherit" onClick={handleShowRecordList}>
Historial de jugadas
</Button>

</Toolbar>
</AppBar>
)}
Expand All @@ -94,8 +117,13 @@ const Login = ({setLogged}) => {
showQuestionList ? (
<GeneratedQuestionsList />
) :

showRecordList ? (
<RecordList username={username} />
)

:
(

<div>
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
Hello {username}!
Expand Down
Loading

0 comments on commit 32a1ee4

Please sign in to comment.