Ignore:
Timestamp:
02/07/22 21:26:03 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
main
Children:
0226942
Parents:
7f36551 (diff), 3c0f9a9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Mato-77 <56981531+Mato-77@…> (02/07/22 21:26:03)
git-committer:
GitHub <noreply@…> (02/07/22 21:26:03)
Message:

Merge pull request #2 from partaloski/master

Added genre liking, fixed counter, improved paging, improved searches

Location:
src/main/java/com/wediscussmovies/project/service/impl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java

    r7f36551 rad4243e  
    11package com.wediscussmovies.project.service.impl;
    22
     3import com.wediscussmovies.project.model.User;
    34import com.wediscussmovies.project.model.exception.GenreNotExistException;
     5import com.wediscussmovies.project.model.exception.UserNotExistException;
     6import com.wediscussmovies.project.model.primarykeys.GenreLikesPK;
     7import com.wediscussmovies.project.model.primarykeys.UserGenresPK;
     8import com.wediscussmovies.project.model.relation.MovieLikes;
     9import com.wediscussmovies.project.model.relation.UserGenres;
    410import com.wediscussmovies.project.querymodels.GenreLikes;
     11import com.wediscussmovies.project.repository.GenreLikesRepository;
    512import com.wediscussmovies.project.repository.GenreRepository;
    613import com.wediscussmovies.project.model.Genre;
     14import com.wediscussmovies.project.repository.UserRepository;
    715import com.wediscussmovies.project.service.GenreService;
    816import org.springframework.stereotype.Service;
     
    1321public class GenreServiceImpl implements GenreService {
    1422    private final GenreRepository genreRepository;
     23    private final UserRepository userRepository;
     24    private final GenreLikesRepository genreLikesRepository;
    1525
    16     public GenreServiceImpl(GenreRepository genreRepository) {
     26
     27    public GenreServiceImpl(GenreRepository genreRepository, UserRepository userRepository, GenreLikesRepository genreLikesRepository) {
    1728        this.genreRepository = genreRepository;
     29        this.userRepository = userRepository;
     30        this.genreLikesRepository = genreLikesRepository;
    1831    }
    1932
     
    3649    @Override
    3750    public List<GenreLikes> findAllWithLikes() {
    38         return this.genreRepository.findAllWithLikes();
     51        List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes();
     52        genreLikesList.sort(GenreLikes.sorter);
     53        return genreLikesList;
    3954    }
    4055
     
    4358        return this.genreRepository.findAll();
    4459    }
     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    }
    4573}
  • src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java

    r7f36551 rad4243e  
    7676
    7777    @Override
     78    public List<Integer> listAllIds() {
     79        return this.movieRepository.findAllMovieIds();
     80    }
     81
     82    @Override
    7883    @Transactional
    7984    public Movie save(String title, String description, String imageUrl,
  • src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java

    r7f36551 rad4243e  
    99import com.wediscussmovies.project.model.primarykeys.PersonRatesPK;
    1010import com.wediscussmovies.project.model.relation.MovieActors;
    11 import com.wediscussmovies.project.model.relation.MovieRates;
    1211import 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;
     12import com.wediscussmovies.project.repository.*;
    1713import com.wediscussmovies.project.model.Person;
    1814import com.wediscussmovies.project.service.PersonService;
     
    3228    private final MovieActorsRepository movieActorsRepository;
    3329    private final PersonRatesRepository personRatesRepository;
    34 
    3530
    3631    public PersonServiceImpl(PersonRepository personRepository,
     
    156151
    157152
     153
     154
    158155    private void addActorForMovies(Person person, List<Integer> movieIds){
    159156
Note: See TracChangeset for help on using the changeset viewer.