Ignore:
Timestamp:
02/07/22 19:57:58 (3 years ago)
Author:
Petar Partaloski <ppartaloski@…>
Branches:
main
Children:
ad4243e, c02189f
Parents:
7f36551
Message:

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

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  
    1414    Genre save(String genreName);
    1515    List<GenreLikes> findAllWithLikes();
     16    void likeGenre(Integer genreId,Integer userId);
     17    void unlikeGenre(Integer genreId,Integer userId);
    1618
    1719}
  • src/main/java/com/wediscussmovies/project/service/MovieService.java

    r7f36551 r3c0f9a9  
    66import com.wediscussmovies.project.model.Person;
    77import com.wediscussmovies.project.model.User;
     8import org.springframework.data.jpa.repository.Query;
    89
    910import java.sql.Date;
     
    1617     List<Movie> searchByTitle(String title);
    1718     Movie findById(Integer id);
     19     List<Integer> listAllIds();
    1820     Movie save(String title, String description, String imageUrl, Date airingDate,Double  rating,
    1921                Integer directorId,List<Integer> actorIds,List<Integer> genreIds);
  • src/main/java/com/wediscussmovies/project/service/PersonService.java

    r7f36551 r3c0f9a9  
    55import com.wediscussmovies.project.model.Person;
    66import com.wediscussmovies.project.model.User;
     7import com.wediscussmovies.project.model.relation.MovieLikes;
    78
    89import java.sql.Date;
    910import java.util.List;
     11import java.util.stream.Collectors;
    1012
    1113public interface PersonService {
     
    2729    void deleteById(Integer id);
    2830    void addGradePerson(Integer personId, User user, Grade grade);
    29 
    3031}
  • src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java

    r7f36551 r3c0f9a9  
    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 r3c0f9a9  
    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 r3c0f9a9  
    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.