src/main/java/com/webcheckers/ui/GetHomeRoute.java
/**
     * Render the WebCheckers Home page.
     *
     * @param request  the HTTP request
     * @param response the HTTP response
     * @return the rendered HTML for the Home page
     */
Render the WebCheckers Home page.
@param request  the HTTP request
@param response the HTTP response
@return the rendered HTML for the Home page
Render the WebCheckers Home page . @param request the HTTP request @param response the HTTP response @return the rendered HTML for the Home page
@Override
    public Object handle(Request request, Response response) {
        LOG.finer("GetHomeRoute is invoked.");
        Map<String, Object> vm = new HashMap<>();
        vm.put("title", "Welcome!");
        vm.put("message", WELCOME_MSG);
        vm.put("statMessage", lobby.getMessage());
        vm.put("lobby", lobby.getInLobbyPlayers());
        Player player = request.session().attribute("user");
        for (Player p : lobby.getActivePlayers()) {
            if (!p.equals(player)) {
                request.session().attribute("opponent", p);
                lobby.getInGame().add(p);
            }
        }
        if (this.lobby.getActivePlayers().size() == 2) {
            if (this.lobby.getActivePlayers().contains(player)) {
                lobby.getInGame().add(player);
                response.redirect("/game");
                return null;
            }
        }
        if ( request.queryParams("inGame") != null ){
            vm.put("message", Message.error("This Player is already in a Game"));
        }
        vm.put("currentUser", player);
        return templateEngine.render(new ModelAndView(vm , "home.ftl"));
  }
@ Override public Object handle ( Request request , Response response ) { LOG . finer ( "GetHomeRoute is invoked." ) ; Map < String , Object > vm = new HashMap < > ( ) ; vm . put ( "title" , "Welcome!" ) ; vm . put ( "message" , WELCOME_MSG ) ; vm . put ( "statMessage" , lobby . getMessage ( ) ) ; vm . put ( "lobby" , lobby . getInLobbyPlayers ( ) ) ; Player player = request . session ( ) . attribute ( "user" ) ; for ( Player p : lobby . getActivePlayers ( ) ) { if ( ! p . equals ( player ) ) { request . session ( ) . attribute ( "opponent" , p ) ; lobby . getInGame ( ) . add ( p ) ; } } if ( this . lobby . getActivePlayers ( ) . size ( ) == 2 ) { if ( this . lobby . getActivePlayers ( ) . contains ( player ) ) { lobby . getInGame ( ) . add ( player ) ; response . redirect ( "/game" ) ; return null ; } } if ( request . queryParams ( "inGame" ) != null ) { vm . put ( "message" , Message . error ( "This Player is already in a Game" ) ) ; } vm . put ( "currentUser" , player ) ; return templateEngine . render ( new ModelAndView ( vm , "home.ftl" ) ) ; }
Render the WebCheckers Home page.
Render the WebCheckers Home page .
// display a user message in the Home page