From af999eb0c38abf74c0c1b4d32939920846395f06 Mon Sep 17 00:00:00 2001 From: uo288061 Date: Thu, 25 Apr 2024 12:55:25 +0200 Subject: [PATCH] cleaning code --- .../uniovi/controllers/GameController.java | 59 +------------------ .../uniovi/entities/MultiplayerSession.java | 3 +- .../MultiplayerSessionRepository.java | 5 -- .../services/impl/MultiplayerSessionImpl.java | 9 +-- src/main/resources/messages.properties | 2 +- src/main/resources/messages_en.properties | 2 + src/main/resources/messages_es.properties | 2 + src/main/resources/messages_fr.properties | 1 + .../templates/game/multiplayerGame.html | 3 - .../templates/ranking/multiplayerRanking.html | 6 ++ 10 files changed, 18 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/uniovi/controllers/GameController.java b/src/main/java/com/uniovi/controllers/GameController.java index 25233374..a28f181d 100644 --- a/src/main/java/com/uniovi/controllers/GameController.java +++ b/src/main/java/com/uniovi/controllers/GameController.java @@ -65,9 +65,6 @@ public String getGame(HttpSession session, Model model, Principal principal) { return "game/basicGame"; } - - - @GetMapping("/multiplayerGame") public String getMultiplayerGame() { return "game/multiplayerGame"; @@ -121,50 +118,10 @@ public String startMultiplayerGame(HttpSession session, Model model, Principal p return "game/basicGame"; } -// @GetMapping("/games/multiFinished") -// public String createFinishedLobby( HttpSession session, Model model) { -// int code = Integer.parseInt((String)session.getAttribute("multiplayerCode")); -// List players=playerService.getUsersByMultiplayerCode(code); -// model.addAttribute("players",players); -// model.addAttribute("code",session.getAttribute("multiplayerCode")); -// session.removeAttribute("gameSession"); -// return "/game/multiFinished"; -// } - - -// @GetMapping("/multiplayerGame/finishedGame") -// public String goToFinishedLobby(HttpSession session,Principal principal) { -// Optional player = playerService.getUserByUsername(principal.getName()); -// Player p = player.orElse(null); -// GameSession gameSession = (GameSession) session.getAttribute("gameSession"); -// playerService.setScoreMultiplayerCode(p.getId(),""+gameSession.getScore()); -// return "redirect:/game/multiFinished"; -// } -// - - -// @GetMapping("/game/multiFinished/{code}") -// @ResponseBody -// public Map updateFinishedGame(@PathVariable String code) { -// List players = playerService.getUsersByMultiplayerCode(Integer.parseInt(code)); -// Map playerInfo = new HashMap<>(); -// for (Player player : players) { -// String playerName = player.getUsername(); -// String playerScore = player.getScoreMultiplayerCode(); -// if(playerScore==null){ -// playerScore="N/A"; -// } -// playerInfo.put(playerName, playerScore); -// } -// return playerInfo; -// } - @GetMapping("/multiplayerGame/endGame/{code}") public String endMultiplayerGame(Model model,@PathVariable String code) { -// List playersWithScores =multiplayerSessionService.getPlayersWithScores(Integer.parseInt(code)); -// model.addAttribute("MultiplayerRanking", playersWithScores); - model.addAttribute("code",code); - return "ranking/multiplayerRanking"; + model.addAttribute("code",code); + return "ranking/multiplayerRanking"; } @GetMapping("/endGameList/{code}") @ResponseBody @@ -175,7 +132,7 @@ public Map endMultiplayerGameTable(@PathVariable String code) { String playerName = player.getKey().getUsername(); String playerScoreValue; if(player.getValue()==-1){ - playerScoreValue="N/A"; //estaria bien q pusiese jugagando pero internazionalizadp + playerScoreValue="N/A"; }else{ playerScoreValue=""+player.getValue(); } @@ -184,8 +141,6 @@ public Map endMultiplayerGameTable(@PathVariable String code) { return playersNameWithScore; } - - @GetMapping("/game/lobby/{code}") @ResponseBody public List updatePlayerList(@PathVariable String code) { @@ -208,14 +163,9 @@ public String createLobby( HttpSession session, Model model) { @GetMapping("/game/startMultiplayerGame") public String startMultiplayerGame( HttpSession session, Model model) { - //La idea seria q dando uno al boton de empezar empezasen todos return "/game/lobby"; } - - - - /** * This method is used to check the answer for a specific question * @param idQuestion The id of the question. @@ -286,9 +236,6 @@ public String updateGame(Model model, HttpSession session, Principal principal) playerService.setScoreMultiplayerCode(p.getId(),""+gameSession.getScore()); multiplayerSessionService.changeScore(p.getMultiplayerCode()+"",p.getId(),gameSession.getScore()); isMultiPlayer=false; - //return "game/multiplayerGame/endGame/"+p.getMultiplayerCode(); - //return "redirect:multiplayerGame/endGame/"+p.getMultiplayerCode(); - //return "redirect:multiplayerGame/endGame/"+p.getMultiplayerCode(); return "game/multiFinished"; } if (nextQuestion == null) { diff --git a/src/main/java/com/uniovi/entities/MultiplayerSession.java b/src/main/java/com/uniovi/entities/MultiplayerSession.java index e80d72bf..e9b77a5c 100644 --- a/src/main/java/com/uniovi/entities/MultiplayerSession.java +++ b/src/main/java/com/uniovi/entities/MultiplayerSession.java @@ -19,8 +19,7 @@ public class MultiplayerSession { private Long id; @Column private String multiplayerCode; - //@ManyToMany - //private Set players =new HashSet<>(); + @ElementCollection @Column private Map playerScores = new HashMap<>(); diff --git a/src/main/java/com/uniovi/repositories/MultiplayerSessionRepository.java b/src/main/java/com/uniovi/repositories/MultiplayerSessionRepository.java index 01a5b114..fd9e926e 100644 --- a/src/main/java/com/uniovi/repositories/MultiplayerSessionRepository.java +++ b/src/main/java/com/uniovi/repositories/MultiplayerSessionRepository.java @@ -12,11 +12,6 @@ import java.util.List; public interface MultiplayerSessionRepository extends CrudRepository { - //List findAll(); - -// @Query("SELECT m FROM MultiplayerSession m JOIN FETCH m.playerScores p WHERE m.multiplayerCode = :multiplayerCode ORDER BY p.scoreMultiplayerCode") -// Page findPlayersByMultiplayerCode(Pageable pageable, String multiplayerCode); - MultiplayerSession findByMultiplayerCode(String code); } diff --git a/src/main/java/com/uniovi/services/impl/MultiplayerSessionImpl.java b/src/main/java/com/uniovi/services/impl/MultiplayerSessionImpl.java index bd05d178..05acec97 100644 --- a/src/main/java/com/uniovi/services/impl/MultiplayerSessionImpl.java +++ b/src/main/java/com/uniovi/services/impl/MultiplayerSessionImpl.java @@ -14,8 +14,8 @@ @Service public class MultiplayerSessionImpl implements MultiplayerSessionService { - private PlayerRepository playerRepository; - private MultiplayerSessionRepository multiplayerSessionRepository; + private final PlayerRepository playerRepository; + private final MultiplayerSessionRepository multiplayerSessionRepository; public MultiplayerSessionImpl(PlayerRepository playerRepository, MultiplayerSessionRepository multiplayerSessionRepository) { @@ -23,11 +23,6 @@ public MultiplayerSessionImpl(PlayerRepository playerRepository, MultiplayerSess this.multiplayerSessionRepository = multiplayerSessionRepository; } -// @Override -// public Page getMultiplayerPlayerRanking(Pageable pageable, int multiplayerCode) { -// return multiplayerSessionRepository.findPlayersByMultiplayerCode(pageable, ""+multiplayerCode); -// } - @Override public Map getPlayersWithScores(int multiplayerCode) { MultiplayerSession session = multiplayerSessionRepository.findByMultiplayerCode(String.valueOf(multiplayerCode)); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 7a991f88..2c2e4c47 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -105,7 +105,7 @@ multi.results =Ver resultados # -------------------Statements for the multiFinished.html file--------------------- multi.finished= Partida finalizada multi.points = Puntuaciones - +multi.menu = Ir a la página de inicio # -------------------Statements for the apiHome.html file--------------------- api.doc.title=Documentación de la API api.doc.description=Esta es la documentación de la API de WIQ. Aquí puedes encontrar información sobre los recursos disponibles, los parámetros que aceptan y los ejemplos de uso. diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 40a630b2..5a2d0015 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -107,6 +107,8 @@ multi.results = See results # -------------------Statements for the multiFinished.html file--------------------- multi.finished= Finished game multi.points = Points +multi.menu =Go to home page + # -------------------Statements for the apiHome.html file--------------------- api.doc.title=API Documentation diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index bc94b7b2..bdbaca5c 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -108,6 +108,8 @@ multi.results =Ver resultados # -------------------Statements for the multiFinished.html file--------------------- multi.finished= Partida finalizada multi.points = Puntuaciones +multi.menu = Ir a la página de inicio + # -------------------Statements for the apiHome.html file--------------------- api.doc.title=Documentación de la API diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index b9c54eee..8316898a 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -101,6 +101,7 @@ multi.results=Voir les résultats # -------------------Statements for the multiFinished.html file--------------------- multi.finished= Jeu terminé multi.points = Points +multi.menu =aller à la page d'accueil # -------------------Statements for the apiHome.html file--------------------- diff --git a/src/main/resources/templates/game/multiplayerGame.html b/src/main/resources/templates/game/multiplayerGame.html index 1be2cbb6..81af9294 100644 --- a/src/main/resources/templates/game/multiplayerGame.html +++ b/src/main/resources/templates/game/multiplayerGame.html @@ -11,13 +11,10 @@
-
-

diff --git a/src/main/resources/templates/ranking/multiplayerRanking.html b/src/main/resources/templates/ranking/multiplayerRanking.html index e47b2963..5fc16703 100644 --- a/src/main/resources/templates/ranking/multiplayerRanking.html +++ b/src/main/resources/templates/ranking/multiplayerRanking.html @@ -14,6 +14,12 @@

+ +