Changeset c02189f in Git for src/main/java
- Timestamp:
- 02/08/22 20:13:23 (3 years ago)
- Branches:
- main
- Children:
- 0226942, 3fe36de
- Parents:
- 3c0f9a9
- Location:
- src/main/java/com/wediscussmovies/project
- Files:
-
- 5 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/configuration/SecurityConfig.java
r3c0f9a9 rc02189f 29 29 http.csrf().disable() 30 30 .authorizeRequests() 31 .antMatchers("/movies","/movies/**/","/actors","/persons/**/","/directors","/discussions","/discussions/**/","/discussions/all/**/","/replies","/register","/genres", "/css/**", "/js/**").permitAll()31 .antMatchers("/movies","/movies/**/","/actors","/persons/**/","/directors","/discussions","/discussions/**/","/discussions/all/**/","/replies","/register","/genres", "/css/**","/img/**", "/js/**").permitAll() 32 32 .anyRequest() 33 33 .authenticated() -
src/main/java/com/wediscussmovies/project/model/Genre.java
r3c0f9a9 rc02189f 22 22 } 23 23 24 public Genre(int genreId, String genreType) { 25 this.genreId = genreId; 26 this.genreType = genreType; 27 } 28 24 29 public Genre(String genreType) { 25 30 this.genreType = genreType; -
src/main/java/com/wediscussmovies/project/model/Movie.java
r3c0f9a9 rc02189f 66 66 } 67 67 68 public Movie(int movieId, String title, Double imdbRating, String imageUrl) { 69 this.movieId = movieId; 70 this.title = title; 71 this.imdbRating = imdbRating; 72 this.imageUrl = imageUrl; 73 } 74 75 public String getDateFormatted(){ 76 String dob = airingDate.toString(); 77 String [] parts = dob.split("-"); 78 return parts[2]+"/"+parts[1]+"/"+parts[0]; 79 } 80 68 81 @Override 69 82 public boolean equals(Object o) { -
src/main/java/com/wediscussmovies/project/model/Person.java
r3c0f9a9 rc02189f 6 6 7 7 import javax.persistence.*; 8 import javax.swing.text.DateFormatter; 8 9 import java.sql.Date; 10 import java.time.LocalDate; 11 import java.time.format.DateTimeFormatter; 9 12 import java.util.Collection; 10 13 … … 73 76 74 77 78 public String getDateFormatted(){ 79 String dob = dateOfBirth.toString(); 80 String [] parts = dob.split("-"); 81 return parts[2]+"/"+parts[1]+"/"+parts[0]; 82 } 83 75 84 76 85 public Person(String name, String surname, Character type, Date dateOfBirth, String imageUrl, String description) { -
src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java
r3c0f9a9 rc02189f 4 4 import com.wediscussmovies.project.model.Movie; 5 5 import com.wediscussmovies.project.model.Person; 6 import com.wediscussmovies.project.querymodels.DiscussionLikes; 7 import com.wediscussmovies.project.querymodels.GenreLikes; 6 8 import org.springframework.data.jpa.repository.JpaRepository; 9 import org.springframework.data.jpa.repository.Query; 7 10 import org.springframework.stereotype.Repository; 8 11 12 import javax.transaction.Transactional; 9 13 import java.util.List; 10 14 … … 14 18 List<Discussion> findAllByMovie(Movie movie); 15 19 List<Discussion> findAllByPerson (Person person); 20 21 @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikes(d.discussionId, count(dl.id.userId)) from Discussion d" + 22 " left join DiscussionLikes dl on dl.id.discussionId = d.discussionId" + 23 " group by d.discussionId" + 24 " order by count(dl.id.userId) desc") 25 @Transactional 26 List<DiscussionLikes> findAllWithLikes(); 16 27 } -
src/main/java/com/wediscussmovies/project/repository/GenreRepository.java
r3c0f9a9 rc02189f 28 28 @Transactional 29 29 void insertInto(@Param("user_id")Integer userId, @Param("genre_id")Integer genreId); 30 31 @Query(value = "select new com.wediscussmovies.project.model.Genre (g.genreId, g.genreType) from Genre g" + 32 " ORDER BY g.genreType DESC") 33 List<Genre> findAllSorted(); 30 34 } -
src/main/java/com/wediscussmovies/project/repository/MovieRepository.java
r3c0f9a9 rc02189f 3 3 import com.wediscussmovies.project.model.Movie; 4 4 import com.wediscussmovies.project.model.Person; 5 import com.wediscussmovies.project.querymodels.GenreLikes; 6 import com.wediscussmovies.project.querymodels.MovieLikesQM; 5 7 import org.springframework.data.jpa.repository.JpaRepository; 6 8 import org.springframework.data.jpa.repository.Query; 9 import org.springframework.data.repository.query.Param; 7 10 import org.springframework.stereotype.Repository; 8 11 12 import javax.transaction.Transactional; 9 13 import java.util.List; 14 import java.util.Optional; 10 15 11 16 @Repository … … 16 21 @Query(value="select m.movieId from Movie m") 17 22 List<Integer> findAllMovieIds(); 23 24 @Query(value="select new com.wediscussmovies.project.model.Movie(m.movieId, m.title, m.imdbRating, m.imageUrl) from Movie m" + 25 " where m.movieId = :index") 26 Optional<Movie> findBasicById(@Param("index")Integer index); 27 28 29 @Query(value = "select new com.wediscussmovies.project.querymodels.MovieLikesQM(m.movieId, count(ml.id.userId)) from Movie m" + 30 " left join MovieLikes ml on ml.id.movieId = m.movieId" + 31 " group by m.movieId" + 32 " order by count(ml.id.userId) desc") 33 @Transactional 34 List<MovieLikesQM> findAllWithLikes(); 35 36 @Query(value = "select new com.wediscussmovies.project.querymodels.MovieLikesQM(m.movieId, count(ml.id.userId)) from Movie m" + 37 " left join MovieLikes ml on ml.id.movieId = m.movieId" + 38 " group by m.movieId" + 39 " having m.movieId = :id") 40 @Transactional 41 List<MovieLikesQM> findLikesForMovie(@Param("id") Integer movie_id); 42 43 18 44 } -
src/main/java/com/wediscussmovies/project/service/DiscussionService.java
r3c0f9a9 rc02189f 3 3 import com.wediscussmovies.project.model.Discussion; 4 4 import com.wediscussmovies.project.model.User; 5 import com.wediscussmovies.project.querymodels.DiscussionLikes; 5 6 6 7 import java.util.List; … … 16 17 void unlikeDiscussion(Integer discussionId,Integer userId); 17 18 List<Discussion> findAllForPersonOrMovie(Integer id,Character type); 19 20 List<Discussion> findLikedDiscussionsByUser(User user); 21 22 DiscussionLikes findLikesForDiscussionWithId(int discussionId); 23 18 24 } -
src/main/java/com/wediscussmovies/project/service/MovieService.java
r3c0f9a9 rc02189f 6 6 import com.wediscussmovies.project.model.Person; 7 7 import com.wediscussmovies.project.model.User; 8 import com.wediscussmovies.project.querymodels.MovieLikesQM; 8 9 import org.springframework.data.jpa.repository.Query; 9 10 … … 17 18 List<Movie> searchByTitle(String title); 18 19 Movie findById(Integer id); 20 Movie findBasicById(Integer id); 19 21 List<Integer> listAllIds(); 20 22 Movie save(String title, String description, String imageUrl, Date airingDate,Double rating, … … 35 37 36 38 void addGradeMovie(Integer movieId, User user, Grade grade); 39 40 MovieLikesQM findLikesForMovieById(int movieId); 37 41 } -
src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java
r3c0f9a9 rc02189f 5 5 import com.wediscussmovies.project.model.exception.PersonNotExistException; 6 6 import com.wediscussmovies.project.model.exception.UserNotExistException; 7 import com.wediscussmovies.project.repository.DiscussionRepository; 7 import com.wediscussmovies.project.model.primarykeys.DiscussionLikesPK; 8 import com.wediscussmovies.project.model.relation.DiscussionLikes; 9 import com.wediscussmovies.project.repository.*; 8 10 import com.wediscussmovies.project.model.Discussion; 9 11 import com.wediscussmovies.project.model.Movie; 10 12 import com.wediscussmovies.project.model.Person; 11 13 import com.wediscussmovies.project.model.User; 12 import com.wediscussmovies.project.repository.MovieRepository;13 import com.wediscussmovies.project.repository.PersonRepository;14 import com.wediscussmovies.project.repository.UserRepository;15 14 import com.wediscussmovies.project.service.DiscussionService; 16 import com.wediscussmovies.project.service.MovieService;17 import com.wediscussmovies.project.service.PersonService;18 import com.wediscussmovies.project.service.UserService;19 15 import org.springframework.stereotype.Service; 20 16 21 17 import java.sql.Date; 22 18 import java.time.LocalDate; 19 import java.util.ArrayList; 23 20 import java.util.List; 24 21 … … 27 24 28 25 private final DiscussionRepository discussionRepository; 26 private final DiscussionLikesRepository discussionLikesRepository; 29 27 private final UserRepository userRepository; 30 28 … … 32 30 private final PersonRepository personRepository; 33 31 34 public DiscussionServiceImpl(DiscussionRepository discussionRepository, UserRepository userRepository,32 public DiscussionServiceImpl(DiscussionRepository discussionRepository, DiscussionLikesRepository discussionLikesRepository, UserRepository userRepository, 35 33 MovieRepository movieRepository, PersonRepository personRepository) { 36 34 this.discussionRepository = discussionRepository; 35 this.discussionLikesRepository = discussionLikesRepository; 37 36 this.userRepository = userRepository; 38 37 this.movieRepository = movieRepository; … … 94 93 @Override 95 94 public void likeDiscussion(Integer discussionId, Integer userId) { 96 //ova fali od dijagram 95 Discussion discussion = discussionRepository.findById(discussionId).orElseThrow(() -> new DiscussionNotExistException(discussionId)); 96 User user = userRepository.findById(userId).orElseThrow(() -> new UserNotExistException(userId.toString())); 97 this.discussionLikesRepository.save(new DiscussionLikes(discussion, user)); 98 } 99 100 @Override 101 public List<Discussion> findLikedDiscussionsByUser(User user) { 102 List<DiscussionLikes> likes = discussionLikesRepository.findAllByUser(user); 103 List<Discussion> discussions = new ArrayList<>(); 104 for(DiscussionLikes dl: likes){ 105 discussions.add(dl.getDiscussion()); 106 } 107 return discussions; 97 108 } 98 109 99 110 @Override 100 111 public void unlikeDiscussion(Integer discussionId, Integer userId) { 101 // ova fali od dijagram 112 DiscussionLikesPK pk = new DiscussionLikesPK(discussionId, userId); 113 this.discussionLikesRepository.deleteById(pk); 102 114 } 115 116 @Override 117 public com.wediscussmovies.project.querymodels.DiscussionLikes findLikesForDiscussionWithId(int discussionId) { 118 return discussionRepository.findAllWithLikes().stream().filter(d -> d.getDiscussionId().equals(discussionId)).findFirst().get(); 119 } 120 103 121 104 122 @Override -
src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
r3c0f9a9 rc02189f 56 56 @Override 57 57 public List<Genre> findAll() { 58 return this.genreRepository.findAll ();58 return this.genreRepository.findAllSorted(); 59 59 } 60 60 -
src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java
r3c0f9a9 rc02189f 13 13 import com.wediscussmovies.project.model.relation.MovieLikes; 14 14 import com.wediscussmovies.project.model.relation.MovieRates; 15 import com.wediscussmovies.project.querymodels.MovieLikesQM; 15 16 import com.wediscussmovies.project.repository.*; 16 17 import com.wediscussmovies.project.model.exception.MovieIdNotFoundException; … … 73 74 public Movie findById(Integer id) { 74 75 return this.movieRepository.findById(id).orElseThrow(() -> new MovieIdNotFoundException(id)); 76 } 77 78 @Override 79 public Movie findBasicById(Integer id) { 80 return this.movieRepository.findBasicById(id).orElseThrow(() -> new MovieIdNotFoundException(id)); 81 } 82 83 @Override 84 public MovieLikesQM findLikesForMovieById(int movieId) { 85 return this.movieRepository.findLikesForMovie(movieId).get(0); 75 86 } 76 87 -
src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java
r3c0f9a9 rc02189f 9 9 import com.wediscussmovies.project.model.primarykeys.PersonRatesPK; 10 10 import com.wediscussmovies.project.model.relation.MovieActors; 11 import com.wediscussmovies.project.model.relation.MovieLikes; 11 12 import com.wediscussmovies.project.model.relation.PersonRates; 12 13 import com.wediscussmovies.project.repository.*; … … 28 29 private final MovieActorsRepository movieActorsRepository; 29 30 private final PersonRatesRepository personRatesRepository; 30 31 31 public PersonServiceImpl(PersonRepository personRepository, 32 32 MovieRepository movieRepository, MovieActorsRepository movieActorsRepository, … … 152 152 153 153 154 155 154 private void addActorForMovies(Person person, List<Integer> movieIds){ 156 155 -
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.