From abb7c8a742dfb30b8bcce21283da54adc596b888 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Thu, 28 Mar 2024 16:34:48 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20historial=20de=20partidas=20reci?= =?UTF-8?q?entes=20en=20el=20perfil=20del=20usuario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/gateway-service.js | 15 ++++++++++++ users/userservice/user-model.js | 1 + users/userservice/user-service.js | 22 +++++++++++++++++ webapp/src/pages/Bateria/Bateria.js | 6 +++++ webapp/src/pages/Clasico/Clasico.js | 6 +++++ webapp/src/pages/Perfil/Perfil.js | 38 ++++++++++++++++++++++++++++- webapp/src/pages/Stats/Stats.js | 1 - 7 files changed, 87 insertions(+), 2 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 8afb9258..c8de682a 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -68,6 +68,21 @@ app.get("/userInfo", async (req, res) => { } }); +app.post("/saveGameList", async (req, res) => { + try { + // Forward the save game request to the stats service + const gameResponse = await axios.post( + userServiceUrl + "/saveGameList", + req.body + ); + res.json(gameResponse.data); + } catch (error) { + res + .status(error.response.status) + .json({ error: error.response.data.error }); + } +}); + app.get("/questions", async (req, res) => { try { // Forward the question request to the question service diff --git a/users/userservice/user-model.js b/users/userservice/user-model.js index 3add662e..5204bc65 100644 --- a/users/userservice/user-model.js +++ b/users/userservice/user-model.js @@ -14,6 +14,7 @@ const userSchema = new mongoose.Schema({ default: Date.now, }, games: [{ + gamemode: String, correctAnswers: Number, incorrectAnswers: Number, points: Number, diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index c1f9d6a9..4a483b8c 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -54,6 +54,28 @@ app.get('/userInfo', async (req, res) => { res.status(400).json({ error: error.message }); }}); +app.post("/saveGameList", async (req, res) => { + try { + const username = req.body.username; + const gamemode = req.body.gameMode; + const gameData = req.body.gameData; + + let user = await User.findOne({ username: username }); + + if (!user) { + return res.status(404).json({ error: "Usuario no encontrado" }); + } + const gameDataWithGamemode = { ...gameData, gamemode }; + user.games.push(gameDataWithGamemode); + + await user.save(); + + res.json({ message: "Partida guardada exitosamente" }); + } catch (error) { + res.status(400).json({ error: "Error al guardar partida en la lista: " + error.message }); + } +}); + const server = app.listen(port, () => { console.log(`User Service listening at http://localhost:${port}`); }); diff --git a/webapp/src/pages/Bateria/Bateria.js b/webapp/src/pages/Bateria/Bateria.js index 707cfe9a..57ea4a54 100644 --- a/webapp/src/pages/Bateria/Bateria.js +++ b/webapp/src/pages/Bateria/Bateria.js @@ -87,6 +87,12 @@ const JuegoPreguntas = () => { } 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); + } catch (error) { + console.error("Error al guardar el juego:", error); + } } useEffect(() => { diff --git a/webapp/src/pages/Clasico/Clasico.js b/webapp/src/pages/Clasico/Clasico.js index a4464053..f35c5b32 100644 --- a/webapp/src/pages/Clasico/Clasico.js +++ b/webapp/src/pages/Clasico/Clasico.js @@ -170,6 +170,12 @@ const JuegoPreguntas = () => { }, }; + try { + const response = await axios.post(URL + "/saveGameList", newGame); + console.log("Solicitud exitosa:", response.data); + } 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); diff --git a/webapp/src/pages/Perfil/Perfil.js b/webapp/src/pages/Perfil/Perfil.js index c583810b..3c5f4219 100644 --- a/webapp/src/pages/Perfil/Perfil.js +++ b/webapp/src/pages/Perfil/Perfil.js @@ -1,5 +1,7 @@ -import { Box, VStack, Heading, Text, Center, Spinner } from "@chakra-ui/react"; +import { Box, VStack, Heading, Text, Center, Spinner, Table, Thead, Tbody, Tr, Th, Td } from "@chakra-ui/react"; import React, { useEffect, useState } from "react"; +import Nav from "../../components/Nav/Nav.js"; +import Footer from "../../components/Footer/Footer.js"; import axios from "axios"; const Perfil = () => { @@ -24,6 +26,8 @@ const Perfil = () => { }, []); return ( + <> +