Skip to content

Commit

Permalink
Merge branch 'master' into 144-eliminar-spanglish
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 authored Apr 27, 2024
2 parents 4332767 + 8655622 commit 820600d
Show file tree
Hide file tree
Showing 21 changed files with 497 additions and 64 deletions.
431 changes: 424 additions & 7 deletions gatewayservice/openapi.yaml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions statsservice/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ app.post("/saveGame", async (req, res) => {
);
}

res.status(200).json({ message: "Partida guardada exitosamente" });
res.status(200).json({ message: "Game saved successfully" });
} else {
throw new Error("Invalid game mode");
}
} catch (error) {
res.status(400).json({ error: "Error al guardar juego: " + error.message });
res.status(400).json({ error: "Error while saving game: " + error.message });
}
});

Expand All @@ -121,7 +121,7 @@ app.get("/stats", async (req, res) => {
} catch (error) {
res
.status(400)
.json({ error: "Error al obtener las estadísticas:" + error.message });
.json({ error: "Error getting stats:" + error.message });
}
});

Expand All @@ -131,23 +131,23 @@ app.get("/ranking", async (req, res) => {
let gamemode = req.query.gamemode;

let data = await Stats.find({ gamemode: gamemode })
.sort(sortBy)
.limit(10);
.sort(sortBy === 'avgTime' ? { [sortBy]: 1 } : { [sortBy]: -1 })
.limit(10);

if (data && data.length > 0) {
data = data.map((stat) => ({
username: stat.username,
[sortBy]: stat[sortBy],
}));
} else {
throw new Error("No se encontraron estadísticas");
throw new Error("No stats found");
}

res.status(200).json(data);
} catch (error) {
res
.status(400)
.json({ error: "Error al obtener el ranking: " + error.message });
.json({ error: "Error getting ranking: " + error.message });
}
});

Expand Down
11 changes: 5 additions & 6 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ app.post("/adduser", async (req, res) => {
// Route to get all users
app.get("/users", async (req, res) => {
try {
const users = await User.find();
console.log(users);
const users = await User.find({}, { password: 0});
res.status(200).json(users);
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
Expand Down Expand Up @@ -246,7 +245,7 @@ app.get("/userGames", async (req, res) => {
try {
const username = req.query.user;
if(!username){
return res.status(400).json({ error: "Nombre inválido" });
return res.status(400).json({ error: "Invalid name" });
}
const user = await User.findOne({ username:
username,
Expand Down Expand Up @@ -309,7 +308,7 @@ app.get('/group/:groupName', async (req, res) => {

res.status(200).json({ group });
} catch (error) {
res.status(400).json({ error: error.message });
res.status(500).json({ error: error.message });
}
});

Expand Down Expand Up @@ -343,7 +342,7 @@ app.post('/group/add', async (req, res) => {

res.status(200).json({ message: 'Group created successfully' });
} catch (error) {
res.status(400).json({ error: error.message });
res.status(500).json({ error: error.message });
}
});

Expand Down Expand Up @@ -374,7 +373,7 @@ app.post('/group/join', async (req, res) => {

res.status(200).json({ message: 'User joined the group successfully' });
} catch (error) {
res.status(400).json({ error: error.message });
res.status(500).json({ error: error.message });
}
});

Expand Down
2 changes: 1 addition & 1 deletion users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe("User Service", () => {
};

const response = await request(app).post("/group/add").send(group);
expect(response.status).toBe(400);
expect(response.status).toBe(500);
expect(response.body).toEqual({ error: "Missing required field: username" });
});

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function App() {
<Route path="/social/misgrupos" element={<UserGroups />} />
<Route path="/social/grupo/:groupName" element={<GroupDetails />} />

<Route path="/perfil/:user" element={<Perfil />} />
<Route path="/perfil" element={<Perfil />} />
<Route path="/history" element={<History />} />
<Route path="/config" element={<Config />} />
</Route>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("Nav Component", () => {
const perfilButton = screen.getByText("Mi perfil");
fireEvent.click(perfilButton);

expect(window.location.pathname).toBe("/perfil/testuser");
expect(window.location.pathname).toBe("/perfil");
});

test("navigates to /sobre when Sobre nosotros button is clicked", () => {
Expand Down
7 changes: 5 additions & 2 deletions webapp/src/components/CustomModal/CustomModal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { Button, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, useDisclosure } from '@chakra-ui/react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from "react-i18next";

const CustomModal = ({ title, text, route }) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const navigate = useNavigate();

const { t } = useTranslation();

return (
<>
<Button onClick={onOpen}>{title}</Button>
Expand All @@ -21,9 +24,9 @@ const CustomModal = ({ title, text, route }) => {

<ModalFooter>
<Button variant='ghost' mr={3} onClick={onClose}>
Cerrar
{t("components.custommodal.close")}
</Button>
<Button colorScheme='blue' onClick={() => navigate(route)}>Jugar</Button>
<Button colorScheme='blue' onClick={() => navigate(route)}>{t("components.custommodal.play")}</Button>
</ModalFooter>
</ModalContent>
</Modal>
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const Login = () => {

const apiEndpoint =
process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000";
console.log(process.env.REACT_APP_API_ENDPOINT);

const loginUser = () => {
axios
Expand All @@ -50,7 +49,6 @@ const Login = () => {
navigate("/home");
})
.catch((err) => {
console.log(err);
setError(err.response.data.error);
});
};
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Nav/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const Nav = () => {
</MenuButton>
<MenuList>
<MenuGroup title={t("components.nav.profile")}>
<MenuItem onClick={() => handleNavigate(`/perfil/${username}`)}>
<MenuItem onClick={() => handleNavigate("/perfil")}>
{t("components.nav.myprofile")}
</MenuItem>
<MenuItem onClick={() => handleNavigate("/history")}>
Expand Down
15 changes: 7 additions & 8 deletions webapp/src/components/Profile/Profile.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Box, VStack, Heading, Text, Center, Spinner, Table, Thead, Tbody, Tr, Th, Td, Avatar } from "@chakra-ui/react";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useParams } from "react-router-dom";

const Perfil = () => {
const Profile = (user) => {
const gatewayUrl = process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000";
const [userData, setUserData] = useState(null);
const [loading, setLoading] = useState(true);
const params = useParams();
const user = params.user || localStorage.getItem("username");
const [error, setError] = useState(null);

const { t } = useTranslation();

const username = (user && user.username) || localStorage.getItem("username");

useEffect(() => {
fetch(gatewayUrl + `/userInfo/${encodeURIComponent(user)}`)
fetch(gatewayUrl + `/userInfo/${username}`)
.then((response) => response.json())
.then((data) => {
setUserData(data);
Expand Down Expand Up @@ -45,7 +44,7 @@ const Perfil = () => {
<>
{userData && (
<>
<Avatar name={user} />
<Avatar name={username} />
<Text justifyContent={"center"}>
<strong>{t('components.profile.name')}</strong> {userData.username}
</Text>
Expand All @@ -56,7 +55,7 @@ const Perfil = () => {
<Heading as="h2" size="md">
{t('components.profile.recentGames')}
</Heading>
<Box overflowX={"scroll"} width={'100%'}>
<Box overflowX={{ base: "scroll", lg: "auto" }} width={'100%'}>
{ userData.games && userData.games.length > 0 ? (
<Table variant="simple">
<Thead>
Expand Down Expand Up @@ -95,5 +94,5 @@ const Perfil = () => {
);
};

export default Perfil;
export default Profile;

10 changes: 8 additions & 2 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"components": {
"custommodal": {
"play": "Jugar",
"close": "Cerrar"
},
"footer": {
"copyright": "Copyright 2024 ® Software Architecture Group 1A"
},
Expand Down Expand Up @@ -87,7 +91,8 @@
"playAgain": "Play Again",
"back": "Back to Menu",
"question": "Question",
"time": "Time Remaining:"
"time": "Time Remaining:",
"send": "Send"
},
"config": {
"title": "Settings",
Expand Down Expand Up @@ -155,7 +160,8 @@
"ratioCorrect": "Correct Ratio (%)",
"avgTime": "Time per Question (s):",
"reboot": "Reset to Default",
"errorText": "An error occurred while retrieving the ranking"
"errorText": "An error occurred while retrieving the ranking",
"noStats":"No stats found for this gamemode"
},
"about": {
"title": "WIQ_es1a Team",
Expand Down
10 changes: 8 additions & 2 deletions webapp/src/locales/es.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"components": {
"custommodal": {
"play": "Jugar",
"close": "Cerrar"
},
"footer": {
"copyright": "Copyright 2024 ® Grupo 1A de Arquitectura del Software"
},
Expand Down Expand Up @@ -87,7 +91,8 @@
"playAgain": "Jugar de nuevo",
"back": "Volver al menú",
"question": "Pregunta",
"time": "Tiempo restante:"
"time": "Tiempo restante:",
"send": "Enviar"
},
"config": {
"title": "Configuración",
Expand Down Expand Up @@ -155,7 +160,8 @@
"ratioCorrect": "Ratio de aciertos (%)",
"avgTime": "Tiempo por pregunta (s):",
"reboot": "Restablecer por defecto",
"errorText": "Ha ocurrido un error al obtener el ranking"
"errorText": "Ha ocurrido un error al obtener el ranking",
"noStats":"No hay estadísticas para este modo de juego"
},
"about": {
"title": "Equipo WIQ_es1a",
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/pages/Calculadora/Calculadora.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const CalculadoraHumana = () => {
{endgame ? (
<Box textAlign="center">
<Heading as="h2">{t('pages.humancalculator.finished')}</Heading>
<p p={2}>Tu puntuación: {points}</p>
<p p={2}>{t("pages.humancalculator.score")} {puntuacion}</p>
<Flex flexDirection={"column"}>
<Button onClick={handleRepeatGame} colorScheme="teal" m={2} data-testid="play-again-button">
{t('pages.humancalculator.playAgain')}
Expand All @@ -195,7 +195,7 @@ const CalculadoraHumana = () => {
/>
<Button mt={3} onClick={() => handleAnswer(Number(valSubmit))} data-testid="submit-button">
{" "}
Enviar{" "}
{t('pages.humancalculator.send')}{" "}
</Button>
<Box textAlign="center" mt={4}>
<p>{t('pages.humancalculator.time')} {Math.floor(timeLeft)}</p>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const JuegoPreguntas = () => {
<p>
{t("pages.classic.time")} {Math.floor(timeLeft)}
</p>
<p>Puntuación: {points}</p>
<p>{t("pages.classic.score")} {puntuacion}</p>
<Box w="100%" bg="gray.100" borderRadius="lg" mt={4}>
<Box
bg="teal.500"
Expand Down
1 change: 0 additions & 1 deletion webapp/src/pages/Config/Config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe("Config Component", () => {
button.click();

const checks = screen.getAllByRole("checkbox");
console.log(checks)
checks[0].checked = true;
button.click();
});
Expand Down
1 change: 0 additions & 1 deletion webapp/src/pages/History/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const History = () => {
.then((response) => response.json())
.then((data) => {
setUserData(data);
console.log(data);
setLoading(false);
})
.catch((error) => {
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/pages/Perfil/Perfil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import Footer from "../../components/Footer/Footer.js";
import Profile from "../../components/Profile/Profile.js";

const Perfil = () => {
const username = localStorage.getItem("username");

return (
<>
<Nav />
<Profile />
<Profile username={username}/>
<Footer />
</>
);
Expand Down
28 changes: 19 additions & 9 deletions webapp/src/pages/Ranking/Ranking.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const Ranking = () => {
fetch(gatewayUrl + `/ranking?gamemode=${gamemode}&filterBy=${filterBy}`)
.then((response) => response.json())
.then((data) => {

setRanking(data);
setIsLoading(false);
})
Expand Down Expand Up @@ -110,13 +109,13 @@ const Ranking = () => {
if (error) {
return (
<>
<Nav/>
<div>
<Heading as="h2">{t('pages.ranking.error')} {error}</Heading>
<p>{t('pages.ranking.errorLabel')}</p>
</div>
<Footer/>
</>
<Nav/>
<div>
<Heading as="h2">{t('pages.ranking.errorText')}</Heading>
<p>{error}</p>
</div>
<Footer/>
</>
);
}

Expand Down Expand Up @@ -154,7 +153,9 @@ const Ranking = () => {
>
{t('pages.ranking.humancalculator')}
</Button>
<Table>
{ranking && ranking.length>0 ? (
<>
<Table>
<Thead>
<Tr>
<Th>{t('pages.ranking.user')}</Th>
Expand All @@ -170,6 +171,15 @@ const Ranking = () => {
))}
</Tbody>
</Table>
</>
):
<>
<div>
<Heading as="h2">{t('pages.ranking.errorText')}</Heading>
<p>{t('pages.ranking.noStats')}</p>
</div>
</>}

</Flex>
<Footer/>
</>
Expand Down
Loading

0 comments on commit 820600d

Please sign in to comment.