Changeset 3c0f9a9 in Git for src/main/java/com/wediscussmovies/project/service
- Timestamp:
- 02/07/22 19:57:58 (3 years ago)
- Branches:
- main
- Children:
- ad4243e, c02189f
- Parents:
- 7f36551
- Location:
- src/main/java/com/wediscussmovies/project/service
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/service/GenreService.java
r7f36551 r3c0f9a9 14 14 Genre save(String genreName); 15 15 List<GenreLikes> findAllWithLikes(); 16 void likeGenre(Integer genreId,Integer userId); 17 void unlikeGenre(Integer genreId,Integer userId); 16 18 17 19 } -
src/main/java/com/wediscussmovies/project/service/MovieService.java
r7f36551 r3c0f9a9 6 6 import com.wediscussmovies.project.model.Person; 7 7 import com.wediscussmovies.project.model.User; 8 import org.springframework.data.jpa.repository.Query; 8 9 9 10 import java.sql.Date; … … 16 17 List<Movie> searchByTitle(String title); 17 18 Movie findById(Integer id); 19 List<Integer> listAllIds(); 18 20 Movie save(String title, String description, String imageUrl, Date airingDate,Double rating, 19 21 Integer directorId,List<Integer> actorIds,List<Integer> genreIds); -
src/main/java/com/wediscussmovies/project/service/PersonService.java
r7f36551 r3c0f9a9 5 5 import com.wediscussmovies.project.model.Person; 6 6 import com.wediscussmovies.project.model.User; 7 import com.wediscussmovies.project.model.relation.MovieLikes; 7 8 8 9 import java.sql.Date; 9 10 import java.util.List; 11 import java.util.stream.Collectors; 10 12 11 13 public interface PersonService { … … 27 29 void deleteById(Integer id); 28 30 void addGradePerson(Integer personId, User user, Grade grade); 29 30 31 } -
src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
r7f36551 r3c0f9a9 1 1 package com.wediscussmovies.project.service.impl; 2 2 3 import com.wediscussmovies.project.model.User; 3 4 import com.wediscussmovies.project.model.exception.GenreNotExistException; 5 import com.wediscussmovies.project.model.exception.UserNotExistException; 6 import com.wediscussmovies.project.model.primarykeys.GenreLikesPK; 7 import com.wediscussmovies.project.model.primarykeys.UserGenresPK; 8 import com.wediscussmovies.project.model.relation.MovieLikes; 9 import com.wediscussmovies.project.model.relation.UserGenres; 4 10 import com.wediscussmovies.project.querymodels.GenreLikes; 11 import com.wediscussmovies.project.repository.GenreLikesRepository; 5 12 import com.wediscussmovies.project.repository.GenreRepository; 6 13 import com.wediscussmovies.project.model.Genre; 14 import com.wediscussmovies.project.repository.UserRepository; 7 15 import com.wediscussmovies.project.service.GenreService; 8 16 import org.springframework.stereotype.Service; … … 13 21 public class GenreServiceImpl implements GenreService { 14 22 private final GenreRepository genreRepository; 23 private final UserRepository userRepository; 24 private final GenreLikesRepository genreLikesRepository; 15 25 16 public GenreServiceImpl(GenreRepository genreRepository) { 26 27 public GenreServiceImpl(GenreRepository genreRepository, UserRepository userRepository, GenreLikesRepository genreLikesRepository) { 17 28 this.genreRepository = genreRepository; 29 this.userRepository = userRepository; 30 this.genreLikesRepository = genreLikesRepository; 18 31 } 19 32 … … 36 49 @Override 37 50 public List<GenreLikes> findAllWithLikes() { 38 return this.genreRepository.findAllWithLikes(); 51 List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes(); 52 genreLikesList.sort(GenreLikes.sorter); 53 return genreLikesList; 39 54 } 40 55 … … 43 58 return this.genreRepository.findAll(); 44 59 } 60 61 @Override 62 public void likeGenre(Integer genreId, Integer userId) { 63 User user = this.userRepository.findById(userId).orElseThrow(() -> new UserNotExistException(userId.toString())); 64 Genre genre = this.genreRepository.findById(genreId).orElseThrow(() -> new GenreNotExistException(genreId)); 65 this.genreLikesRepository.save(new UserGenres(genre, user)); 66 } 67 68 @Override 69 public void unlikeGenre(Integer genreId, Integer userId) { 70 UserGenresPK movieLikesPK = new UserGenresPK(userId, genreId); 71 this.genreLikesRepository.deleteById(movieLikesPK); 72 } 45 73 } -
src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java
r7f36551 r3c0f9a9 76 76 77 77 @Override 78 public List<Integer> listAllIds() { 79 return this.movieRepository.findAllMovieIds(); 80 } 81 82 @Override 78 83 @Transactional 79 84 public Movie save(String title, String description, String imageUrl, -
src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java
r7f36551 r3c0f9a9 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.MovieRates;12 11 import com.wediscussmovies.project.model.relation.PersonRates; 13 import com.wediscussmovies.project.repository.MovieActorsRepository; 14 import com.wediscussmovies.project.repository.MovieRepository; 15 import com.wediscussmovies.project.repository.PersonRatesRepository; 16 import com.wediscussmovies.project.repository.PersonRepository; 12 import com.wediscussmovies.project.repository.*; 17 13 import com.wediscussmovies.project.model.Person; 18 14 import com.wediscussmovies.project.service.PersonService; … … 32 28 private final MovieActorsRepository movieActorsRepository; 33 29 private final PersonRatesRepository personRatesRepository; 34 35 30 36 31 public PersonServiceImpl(PersonRepository personRepository, … … 156 151 157 152 153 154 158 155 private void addActorForMovies(Person person, List<Integer> movieIds){ 159 156
Note:
See TracChangeset
for help on using the changeset viewer.