From 68b7aa50ce58cd67088162bf04c5b70e9184c121 Mon Sep 17 00:00:00 2001 From: kmitresse Date: Tue, 30 Apr 2024 22:14:57 +0200 Subject: [PATCH] fix: devWeb - display all list of played game (profile) --- .../main/java/uppa/project/web/servlet/ProfileServlet.java | 4 ++-- .../src/main/java/uppa/project/web/websocket/GameWS.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/ProfileServlet.java b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/ProfileServlet.java index 9387dfb..e8bf11c 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/ProfileServlet.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/web/servlet/ProfileServlet.java @@ -30,11 +30,11 @@ public class ProfileServlet extends HttpServlet { } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - User user = (User) request.getSession().getAttribute("user"); + User usersession = (User) request.getSession().getAttribute("user"); DAO userDAO = null; try { userDAO = new Game_JPA_DAO_Factory().getDAOUser(); - user = userDAO.findById(user.getId().intValue()); + User user = userDAO.findById(usersession.getId().intValue()); for(Player p : user.getPlayedGames()){ System.out.println("Partie jouée le " + p.getGame().getCreatedAt().toLocaleString()); } diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java b/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java index 7697a42..9be266c 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/web/websocket/GameWS.java @@ -233,7 +233,11 @@ public class GameWS { em.getTransaction().begin(); em.persist(game); - for (Player p : games.get(game)) em.persist(p); + for (Player p : games.get(game)){ + game.addPlayer(p); + p.getUser().addPlayedGame(p); + } + em.persist(game); em.getTransaction().commit(); } }