Skip to content

Commit

Permalink
Index Controller carrouselGames
Browse files Browse the repository at this point in the history
  • Loading branch information
pizarroiker committed Feb 21, 2023
1 parent 4e66849 commit 750e2d8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/src/main/java/app/controller/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import app.service.PurchaseService;

import java.security.Principal;
import java.util.List;

import app.model.Game;
import app.model.User;
import app.service.UserService;

Expand Down Expand Up @@ -44,11 +47,17 @@ public void addAttributes(Model model, HttpServletRequest request) {
} else {
model.addAttribute("logged", false);
}
if (model.containsAttribute("ADMIN") || currentUser == null || purchaseService.purchasedGamesByUser(currentUser).isEmpty()) {
if (model.containsAttribute("admin") || currentUser == null || purchaseService.purchasedGamesByUser(currentUser).isEmpty()) {
model.addAttribute("carrouselGames", gameService.findRecomendnoreg(3));
}else{
String category = gameService.findRecomendCategory(currentUser.getId());
model.addAttribute("carrouselGames", gameService.findRecomendbyCategory(category,currentUser.getId(),3));
List<Game> games = gameService.findRecomendbyCategory(category,currentUser.getId(),3);
if(games.isEmpty()){
games.addAll(gameService.findRecomendnoreg(3));
}else if (games.size() < 3){
games.addAll(gameService.findRecomendnoreg(3-games.size()));
}
model.addAttribute("carrouselGames", games);
}
}

Expand Down

0 comments on commit 750e2d8

Please sign in to comment.