Skip to content

Commit

Permalink
Merge pull request #152 from Arquisoft/hotfixes
Browse files Browse the repository at this point in the history
Hotfixes
  • Loading branch information
CANCI0 authored Apr 27, 2024
2 parents 474fd49 + 269b3bc commit 30e84bc
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 57 deletions.
431 changes: 424 additions & 7 deletions gatewayservice/openapi.yaml

Large diffs are not rendered by default.

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 @@ -291,7 +291,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;

7 changes: 6 additions & 1 deletion 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
7 changes: 6 additions & 1 deletion 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
3 changes: 1 addition & 2 deletions webapp/src/pages/Bateria/Bateria.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ const JuegoPreguntas = () => {

const saveGame = async (endpoint, newGame) => {
try {
const response = await axios.post(URL + endpoint, newGame);
console.log("Solicitud exitosa:", response.data);
await axios.post(URL + endpoint, newGame);
} catch (error) {
console.error("Error al guardar el juego:", error);
}
Expand Down
11 changes: 4 additions & 7 deletions webapp/src/pages/Calculadora/Calculadora.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ const CalculadoraHumana = () => {
}
};
try {
const response = await axios.post(URL + '/saveGame', newGame);
console.log("Solicitud exitosa:", response.data);

await axios.post(URL + '/saveGame', newGame);
} catch (error) {
console.error('Error al guardar el juego:', error);
}
try {
const response = await axios.post(URL + "/saveGameList", newGame);
console.log("Solicitud exitosa:", response.data);
await axios.post(URL + "/saveGameList", newGame);
} catch (error) {
console.error("Error al guardar el juego:", error);
}
Expand Down Expand Up @@ -173,7 +170,7 @@ const CalculadoraHumana = () => {
{juegoTerminado ? (
<Box textAlign="center">
<Heading as="h2">{t('pages.humancalculator.finished')}</Heading>
<p p={2}>Tu puntuación: {puntuacion}</p>
<p p={2}>{t("pages.humancalculator.score")} {puntuacion}</p>
<Flex flexDirection={"column"}>
<Button onClick={handleRepetirJuego} colorScheme="teal" m={2} data-testid="play-again-button">
{t('pages.humancalculator.playAgain')}
Expand All @@ -198,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(tiempoRestante)}</p>
Expand Down
8 changes: 3 additions & 5 deletions webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,15 @@ const JuegoPreguntas = () => {
};

try {
const response = await axios.post(URL + "/saveGameList", newGame);
console.log("Solicitud exitosa:", response.data);
await axios.post(URL + "/saveGameList", newGame);
} catch (error) {
console.error(
"Error al guardar el juego en la lista de partidas:",
error
);
}
try {
const response = await axios.post(URL + "/saveGame", newGame);
console.log("Solicitud exitosa:", response.data);
await axios.post(URL + "/saveGame", newGame);
} catch (error) {
console.error("Error al guardar el juego:", error);
}
Expand Down Expand Up @@ -318,7 +316,7 @@ const JuegoPreguntas = () => {
<p>
{t("pages.classic.time")} {Math.floor(tiempoRestante)}
</p>
<p>Puntuación: {puntuacion}</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
2 changes: 0 additions & 2 deletions webapp/src/pages/Social/FriendsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const FriendList = () => {
return response.json();
})
.then((data) => {
console.log(data);
console.log(data.friends);
setFriends(data.friends);
setIsLoading(false);
})
Expand Down
10 changes: 4 additions & 6 deletions webapp/src/pages/Social/GroupDetails.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { useParams } from "react-router-dom";
import {
Container,
Box,
Expand All @@ -18,7 +18,7 @@ import {
import Nav from "../../components/Nav/Nav.js";
import Footer from "../../components/Footer/Footer.js";
import { useTranslation } from "react-i18next";
import Perfil from "../../components/Profile/Profile.js";
import Profile from "../../components/Profile/Profile.js";


const GroupDetails = () => {
Expand All @@ -29,8 +29,6 @@ const GroupDetails = () => {
const { groupName } = useParams();
const apiEndpoint =
process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000";

const navigate = useNavigate();

useEffect(() => {
fetchGroupDetails();
Expand All @@ -55,15 +53,15 @@ const GroupDetails = () => {
};

const redirectToProfile = (member) => {
navigate(`/perfil/${member.username}`);
setUser(member);
};


if(user){
return (
<>
<Nav />
<Perfil username={user} />
<Profile username={user} />
<Button p={"1rem"} mb={"1rem"} onClick={() => setUser("")}>Volver</Button>
<Footer />
</>
Expand Down
1 change: 0 additions & 1 deletion webapp/src/pages/Social/GroupDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ describe('GroupDetails', () => {
await checks();

const viewProfileButtons = screen.getByTestId('view-profile-button-user1');
console.log(viewProfileButtons);

fireEvent.click(viewProfileButtons);
});
Expand Down

0 comments on commit 30e84bc

Please sign in to comment.