Changeset c02189f in Git for src/main/java/com/wediscussmovies/project/web
- Timestamp:
- 02/08/22 20:13:23 (3 years ago)
- Branches:
- main
- Children:
- 0226942, 3fe36de
- Parents:
- 3c0f9a9
- Location:
- src/main/java/com/wediscussmovies/project/web
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/web/PageFrontMovies.java
r3c0f9a9 rc02189f 32 32 33 33 for(Integer id: movieIds){ 34 movies.add(movieService.findById(id)); 34 //Trying to improve load times by not pulling all things from the database, excluding un-needed stuff 35 // 36 //movies.add(movieService.findById(id)); 37 movies.add(movieService.findBasicById(id)); 35 38 } 36 39 model.addAttribute("page", page); -
src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java
r3c0f9a9 rc02189f 5 5 import com.wediscussmovies.project.model.Reply; 6 6 import com.wediscussmovies.project.model.User; 7 import com.wediscussmovies.project.model.relation.DiscussionLikes; 7 8 import com.wediscussmovies.project.service.DiscussionService; 8 9 import com.wediscussmovies.project.service.MovieService; … … 17 18 import org.springframework.web.bind.annotation.*; 18 19 20 import java.util.ArrayList; 19 21 import java.util.List; 20 22 … … 46 48 model.addAttribute("contentTemplate", "discussionsList"); 47 49 model.addAttribute("user",LoggedUser.getLoggedUser()); 50 this.addModelPropertiesForUser(model); 51 this.addModelPropertiesLikes(model,null, discussions); 48 52 return "template"; 49 53 } … … 62 66 model.addAttribute("user",LoggedUser.getLoggedUser()); 63 67 model.addAttribute("replies",this.replyService.findAllByDiscussion(disc)); 68 addModelPropertiesLikes(model, disc, null); 69 addModelPropertiesForUser(model); 64 70 65 71 return "template"; … … 171 177 172 178 } 179 private void addModelPropertiesForUser(Model model){ 180 User user = LoggedUser.getLoggedUser(); 181 model.addAttribute("likedDiscussions",this.discussionService.findLikedDiscussionsByUser(user)); 182 model.addAttribute("user",user); 183 } 184 private void addModelPropertiesLikes(Model model, Discussion discussion, List<Discussion> discussions){ 185 if(discussion==null){ 186 List<com.wediscussmovies.project.querymodels.DiscussionLikes> discussionLikes = new ArrayList<>(); 187 for(Discussion d: discussions){ 188 discussionLikes.add(discussionService.findLikesForDiscussionWithId(d.getDiscussionId())); 189 } 190 model.addAttribute("likes", discussionLikes); 191 } 192 else{ 193 model.addAttribute("likes",discussionService.findLikesForDiscussionWithId(discussion.getDiscussionId()).getLikes()); 194 } 195 } 173 196 174 197 -
src/main/java/com/wediscussmovies/project/web/controller/MovieController.java
r3c0f9a9 rc02189f 5 5 import com.wediscussmovies.project.model.Person; 6 6 import com.wediscussmovies.project.model.User; 7 import com.wediscussmovies.project.querymodels.MovieLikesQM; 7 8 import com.wediscussmovies.project.service.GenreService; 8 9 import com.wediscussmovies.project.service.MovieService; … … 23 24 import java.time.LocalDate; 24 25 import java.util.ArrayList; 26 import java.util.HashMap; 27 import java.util.LinkedList; 25 28 import java.util.List; 26 29 … … 39 42 40 43 @GetMapping("/old") 41 public String getMovies (@RequestParam(required = false) String titleQuery, Model model,44 public String getMoviesOld(@RequestParam(required = false) String titleQuery, Model model, 42 45 @RequestParam(required = false) String error){ 43 46 List<Movie> movies; … … 56 59 model.addAttribute("movie_rows", movie_rows); 57 60 model.addAttribute("contentTemplate", "moviesList"); 61 model.addAttribute("genres", genreService.findAll()); 58 62 if (error != null && !error.equals(" ")) 59 63 model.addAttribute("error",error); … … 63 67 64 68 @GetMapping 65 public String getMovies Alternative(@RequestParam(required = false) String titleQuery, Model model,69 public String getMovies(@RequestParam(required = false) String titleQuery, Model model, 66 70 @RequestParam(required = false) String error, @RequestParam(required = false) String page){ 67 71 if (page==null){ … … 72 76 List<List<Movie>> movie_rows = new ArrayList<>(); 73 77 DesignFrontMovies.designMovieList(movies,movie_rows); 78 //addModelPropertiesForMoviesLikes(model, movies); 74 79 model.addAttribute("movies", movies); 75 80 model.addAttribute("movie_rows", movie_rows); 81 model.addAttribute("genres", genreService.findAll()); 76 82 model.addAttribute("contentTemplate", "moviesListPaged"); 77 83 if (error != null && !error.equals(" ")) … … 84 90 model.addAttribute("movie", movieService.findById(id)); 85 91 addModelPropertiesForUser(model); 92 model.addAttribute("likes", movieService.findLikesForMovieById(id).getLikes()); 86 93 model.addAttribute("contentTemplate", "movieShow"); 87 94 return "template"; … … 189 196 model.addAttribute("user",user); 190 197 } 198 private void addModelPropertiesForMoviesLikes(Model model, List<Movie> movies){ 199 HashMap<Integer,MovieLikesQM> movieLikes = new HashMap<>(); 200 for(Movie m: movies){ 201 movieLikes.put(m.getMovieId(),movieService.findLikesForMovieById(m.getMovieId())); 202 } 203 model.addAttribute("movieLikes", movieLikes); 204 } 191 205 192 206 } -
src/main/java/com/wediscussmovies/project/web/controller/rest/MovieRestController.java
r3c0f9a9 rc02189f 52 52 public ResponseEntity addGrade(@PathVariable Integer movieId, @RequestBody Grade grade){ 53 53 try { 54 if(grade.getRating() < 5) 55 grade.setRating(5); 56 else if(grade.getRating()>10) 57 grade.setRating(10); 54 58 this.movieService.addGradeMovie(movieId, LoggedUser.getLoggedUser(),grade); 55 59 return ResponseEntity.ok(true);
Note:
See TracChangeset
for help on using the changeset viewer.