Changeset ad4243e in Git for src/main/java/com/wediscussmovies/project/web/controller/GenreController.java
- Timestamp:
- 02/07/22 21:26:03 (3 years ago)
- Branches:
- main
- Children:
- 0226942
- Parents:
- 7f36551 (diff), 3c0f9a9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Mato-77 <56981531+Mato-77@…> (02/07/22 21:26:03)
- git-committer:
- GitHub <noreply@…> (02/07/22 21:26:03)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/web/controller/GenreController.java
r7f36551 rad4243e 1 1 package com.wediscussmovies.project.web.controller; 2 2 3 import com.wediscussmovies.project.LoggedUser; 4 import com.wediscussmovies.project.model.Genre; 5 import com.wediscussmovies.project.model.User; 6 import com.wediscussmovies.project.model.relation.UserGenres; 7 import com.wediscussmovies.project.querymodels.GenreLikes; 8 import com.wediscussmovies.project.repository.GenreLikesRepository; 3 9 import com.wediscussmovies.project.service.GenreService; 4 10 import org.springframework.stereotype.Controller; … … 7 13 import org.springframework.web.bind.annotation.RequestMapping; 8 14 15 import java.util.ArrayList; 16 import java.util.List; 17 9 18 @Controller 10 19 @RequestMapping("/genres") 11 20 public class GenreController { 12 21 private final GenreService genreService; 22 private final GenreLikesRepository genreLikesRepository; 13 23 14 public GenreController(GenreService genreService ) {24 public GenreController(GenreService genreService, GenreLikesRepository genreLikesRepository) { 15 25 this.genreService = genreService; 26 this.genreLikesRepository = genreLikesRepository; 16 27 } 17 28 @GetMapping 18 29 public String getGenres(Model model){ 19 30 model.addAttribute("genres",genreService.findAllWithLikes()); 31 model.addAttribute("allGenres", genreService.findAll()); 20 32 model.addAttribute("contentTemplate","genres"); 33 addModelPropertiesForUser(model); 21 34 return "template"; 22 35 } 36 37 private void addModelPropertiesForUser(Model model){ 38 User user = LoggedUser.getLoggedUser(); 39 List<UserGenres> genreLikesList = this.genreLikesRepository.findAllByUser(user); 40 List<Genre> genres = new ArrayList<>(); 41 for(UserGenres g: genreLikesList){ 42 genres.add(genreService.findById(g.getId().getGenreId())); 43 } 44 model.addAttribute("likedGenres",genres); 45 model.addAttribute("user",user); 46 } 23 47 }
Note:
See TracChangeset
for help on using the changeset viewer.