Changeset 3c0f9a9 in Git for src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
- Timestamp:
- 02/07/22 19:57:58 (3 years ago)
- Branches:
- main
- Children:
- ad4243e, c02189f
- Parents:
- 7f36551
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.