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

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.