diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js
index 23c20b64..4c82eac9 100644
--- a/gatewayservice/gateway-service.js
+++ b/gatewayservice/gateway-service.js
@@ -91,6 +91,17 @@ app.get('/getquestionshistory', async (req, res) => {
}
});
+app.get('/getregisteredusers', async (req, res) => {
+ try {
+ // Create a petition to the URL (le llegará a retrieve-service.js) with the option /getregisteredusers and the req.body params
+ const registeredUsersResponse = await axios.get(userServiceUrl+'/getregisteredusers', req.body);
+ // Return a json response with what we obtained on the petition
+ res.json(registeredUsersResponse.data);
+ } catch (error) {
+ res.status(error.response.status).json({ error: error.response.data.error });
+ }
+});
+
// Read the OpenAPI YAML file synchronously
diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js
index 2cbe99ea..711d49dd 100644
--- a/users/userservice/user-service.js
+++ b/users/userservice/user-service.js
@@ -48,6 +48,17 @@ app.post('/adduser', async (req, res) => {
}
});
+app.get('/getregisteredusers', async (req, res) => {
+ const registeredUsers = await User.find({});
+
+ var solution = [];
+ registeredUsers.forEach(row => {
+ solution.push([row.username,new Date(row.createdAt).toLocaleDateString()]);
+ });
+
+ res.status(200).json(solution);
+});
+
const server = app.listen(port, () => {
console.log(`User Service listening at http://localhost:${port}`);
});
diff --git a/webapp/src/components/MainPage.js b/webapp/src/components/MainPage.js
index 757bf60a..1f70359e 100644
--- a/webapp/src/components/MainPage.js
+++ b/webapp/src/components/MainPage.js
@@ -21,26 +21,34 @@ const MainPage = () => {
navigate(path);
};
+ const handleShowRegisteredUsers = () => {
+ let path= '/RegisteredUsers';
+ navigate(path);
+ };
+
return (
- ¡Bienvenido a WIQ 2024!
+ ¡Bienvenido a WIQ 2024!
- Puedes comenzar la partida o ver tu historial.
+ Puedes comenzar la partida o ver tu historial.
+
diff --git a/webapp/src/components/RegisteredUsers.js b/webapp/src/components/RegisteredUsers.js
new file mode 100644
index 00000000..0ebbe269
--- /dev/null
+++ b/webapp/src/components/RegisteredUsers.js
@@ -0,0 +1,65 @@
+import axios from 'axios';
+import React, { useState, useEffect } from 'react';
+import { useNavigate} from 'react-router-dom';
+import { Container, Button} from '@mui/material';
+
+const RegisteredUsers = () => {
+ const navigate = useNavigate();
+ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
+
+ const [registeredUsers, setRegisteredUsers] = useState([]);
+
+ useEffect(() => {
+ handleShowHistory();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ const handleShowHistory = async () => {
+ try{
+ // It makes a petition to the api and store the response
+ const response = await axios.get(`${apiEndpoint}/getregisteredusers`, { });
+ setRegisteredUsers(response.data);
+ }catch (error){
+ console.error('Error:', error);
+ }
+ }
+
+ const handlePreviousPage = async () => {
+ let path= '/MainPage';
+ navigate(path);
+ }
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
Nombre de usuario
+
Fecha de registro
+
+
+
+ {registeredUsers.map((row, rowIndex) => (
+
+ {row.map((cell, cellIndex) => (
+
{cell}
+ ))}
+
+ ))}
+
+
+
+
+
+ );
+};
+
+export default RegisteredUsers;
\ No newline at end of file
diff --git a/webapp/src/index.js b/webapp/src/index.js
index 9f794123..18eada02 100644
--- a/webapp/src/index.js
+++ b/webapp/src/index.js
@@ -8,6 +8,7 @@ import Game from './components/Game';
import HistoricalData from './components/HistoricalData';
import MainPage from './components/MainPage';
import HistoricalUserData from './components/HistoricalUserData';
+import RegisteredUsers from './components/RegisteredUsers';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
@@ -19,6 +20,7 @@ root.render(
}>
}>
}>
+ }>