Changeset c02189f in Git for src/main/java/com/wediscussmovies/project/service
- Timestamp:
- 02/08/22 20:13:23 (3 years ago)
- Branches:
- main
- Children:
- 0226942, 3fe36de
- Parents:
- 3c0f9a9
- Location:
- src/main/java/com/wediscussmovies/project/service
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.