Index: src/main/java/com/wediscussmovies/project/model/primarykeys/GenreLikesPK.java
===================================================================
--- src/main/java/com/wediscussmovies/project/model/primarykeys/GenreLikesPK.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
+++ src/main/java/com/wediscussmovies/project/model/primarykeys/GenreLikesPK.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -0,0 +1,43 @@
+package com.wediscussmovies.project.model.primarykeys;
+
+import lombok.Data;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import java.io.Serializable;
+
+@Embeddable
+@Data
+public class GenreLikesPK implements Serializable {
+
+    @Column(name = "genre_id")
+    private int genreId;
+
+    @Column(name = "user_id")
+    private int userId;
+
+    public GenreLikesPK() {
+    }
+
+    public GenreLikesPK(int genreId, int userId) {
+        this.genreId = genreId;
+        this.userId = userId;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        GenreLikesPK that = (GenreLikesPK) o;
+
+        return userId == that.userId && genreId == that.genreId;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = genreId;
+        result = 31 * result + userId;
+        return result;
+    }
+}
Index: src/main/java/com/wediscussmovies/project/model/primarykeys/UserGenresPK.java
===================================================================
--- src/main/java/com/wediscussmovies/project/model/primarykeys/UserGenresPK.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/model/primarykeys/UserGenresPK.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -1,3 +1,5 @@
 package com.wediscussmovies.project.model.primarykeys;
+
+import lombok.Data;
 
 import javax.persistence.Column;
@@ -6,4 +8,5 @@
 import java.io.Serializable;
 
+@Data
 @Embeddable
 public class UserGenresPK implements Serializable {
@@ -30,6 +33,4 @@
         UserGenresPK that = (UserGenresPK) o;
 
-
-
         return userId == that.userId && genreId == that.genreId;
     }
Index: src/main/java/com/wediscussmovies/project/querymodels/GenreLikes.java
===================================================================
--- src/main/java/com/wediscussmovies/project/querymodels/GenreLikes.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/querymodels/GenreLikes.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -3,13 +3,35 @@
 import lombok.Data;
 
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import java.util.Comparator;
+import java.util.Objects;
+
 @Data
 public class GenreLikes {
-
+    private Integer genreId;
     private String name;
     private Long likes;
 
-    public GenreLikes(String name, Long likes) {
+    public static Comparator<GenreLikes> sorter = Comparator.comparing(GenreLikes::getLikes).thenComparing(GenreLikes::getName).reversed();
+
+    public GenreLikes(Integer genreId, String name, Long likes) {
+        this.genreId = genreId;
         this.name = name;
         this.likes = likes;
+
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        GenreLikes that = (GenreLikes) o;
+        return Objects.equals(genreId, that.genreId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(genreId);
     }
 }
Index: src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
+++ src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -0,0 +1,18 @@
+package com.wediscussmovies.project.repository;
+
+import com.wediscussmovies.project.model.User;
+import com.wediscussmovies.project.model.primarykeys.GenreLikesPK;
+import com.wediscussmovies.project.model.primarykeys.MovieLikesPK;
+import com.wediscussmovies.project.model.primarykeys.UserGenresPK;
+import com.wediscussmovies.project.model.relation.MovieLikes;
+import com.wediscussmovies.project.model.relation.UserGenres;
+import com.wediscussmovies.project.querymodels.GenreLikes;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface GenreLikesRepository  extends JpaRepository<UserGenres, UserGenresPK> {
+    List<UserGenres> findAllByUser(User user);
+}
Index: src/main/java/com/wediscussmovies/project/repository/GenreRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/GenreRepository.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/repository/GenreRepository.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -4,8 +4,11 @@
 import com.wediscussmovies.project.querymodels.GenreLikes;
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
 import javax.transaction.Transactional;
+import java.sql.Date;
 import java.util.List;
 
@@ -14,9 +17,14 @@
      List<Genre> findAllByGenreType(String genre);
 
-     @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikes(g.genreType, count(ug.id.userId)) from Genre g" +
+     @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikes(g.genreId, g.genreType, count(ug.id.userId)) from Genre g" +
              " left join UserGenres ug on ug.id.genreId = g.genreId" +
-             " group by g.genreType" +
+             " group by g.genreId, g.genreType" +
              " order by count(ug.id.userId) desc")
      @Transactional
      List<GenreLikes> findAllWithLikes();
+
+     @Modifying
+     @Query(value = "insert into project.user_genres (user_id,genre_id) values(:user_id,:genre_id)",nativeQuery = true)
+     @Transactional
+     void insertInto(@Param("user_id")Integer userId, @Param("genre_id")Integer genreId);
 }
Index: src/main/java/com/wediscussmovies/project/repository/MovieRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/MovieRepository.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/repository/MovieRepository.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -4,4 +4,5 @@
 import com.wediscussmovies.project.model.Person;
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Repository;
 
@@ -13,3 +14,5 @@
      List<Movie> findAllByDirector(Person director);
      List<Movie> findAllByDirectorIsNull();
+     @Query(value="select m.movieId from Movie m")
+     List<Integer> findAllMovieIds();
 }
Index: src/main/java/com/wediscussmovies/project/service/GenreService.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/GenreService.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/GenreService.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -14,4 +14,6 @@
     Genre save(String genreName);
     List<GenreLikes> findAllWithLikes();
+    void likeGenre(Integer genreId,Integer userId);
+    void unlikeGenre(Integer genreId,Integer userId);
 
 }
Index: src/main/java/com/wediscussmovies/project/service/MovieService.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/MovieService.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/MovieService.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -6,4 +6,5 @@
 import com.wediscussmovies.project.model.Person;
 import com.wediscussmovies.project.model.User;
+import org.springframework.data.jpa.repository.Query;
 
 import java.sql.Date;
@@ -16,4 +17,5 @@
      List<Movie> searchByTitle(String title);
      Movie findById(Integer id);
+     List<Integer> listAllIds();
      Movie save(String title, String description, String imageUrl, Date airingDate,Double  rating,
                 Integer directorId,List<Integer> actorIds,List<Integer> genreIds);
Index: src/main/java/com/wediscussmovies/project/service/PersonService.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/PersonService.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/PersonService.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -5,7 +5,9 @@
 import com.wediscussmovies.project.model.Person;
 import com.wediscussmovies.project.model.User;
+import com.wediscussmovies.project.model.relation.MovieLikes;
 
 import java.sql.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 public interface PersonService {
@@ -27,4 +29,3 @@
     void deleteById(Integer id);
     void addGradePerson(Integer personId, User user, Grade grade);
-
 }
Index: src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -1,8 +1,16 @@
 package com.wediscussmovies.project.service.impl;
 
+import com.wediscussmovies.project.model.User;
 import com.wediscussmovies.project.model.exception.GenreNotExistException;
+import com.wediscussmovies.project.model.exception.UserNotExistException;
+import com.wediscussmovies.project.model.primarykeys.GenreLikesPK;
+import com.wediscussmovies.project.model.primarykeys.UserGenresPK;
+import com.wediscussmovies.project.model.relation.MovieLikes;
+import com.wediscussmovies.project.model.relation.UserGenres;
 import com.wediscussmovies.project.querymodels.GenreLikes;
+import com.wediscussmovies.project.repository.GenreLikesRepository;
 import com.wediscussmovies.project.repository.GenreRepository;
 import com.wediscussmovies.project.model.Genre;
+import com.wediscussmovies.project.repository.UserRepository;
 import com.wediscussmovies.project.service.GenreService;
 import org.springframework.stereotype.Service;
@@ -13,7 +21,12 @@
 public class GenreServiceImpl implements GenreService {
     private final GenreRepository genreRepository;
+    private final UserRepository userRepository;
+    private final GenreLikesRepository genreLikesRepository;
 
-    public GenreServiceImpl(GenreRepository genreRepository) {
+
+    public GenreServiceImpl(GenreRepository genreRepository, UserRepository userRepository, GenreLikesRepository genreLikesRepository) {
         this.genreRepository = genreRepository;
+        this.userRepository = userRepository;
+        this.genreLikesRepository = genreLikesRepository;
     }
 
@@ -36,5 +49,7 @@
     @Override
     public List<GenreLikes> findAllWithLikes() {
-        return this.genreRepository.findAllWithLikes();
+        List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes();
+        genreLikesList.sort(GenreLikes.sorter);
+        return genreLikesList;
     }
 
@@ -43,3 +58,16 @@
         return this.genreRepository.findAll();
     }
+
+    @Override
+    public void likeGenre(Integer genreId, Integer userId) {
+        User user = this.userRepository.findById(userId).orElseThrow(() -> new UserNotExistException(userId.toString()));
+        Genre genre = this.genreRepository.findById(genreId).orElseThrow(() -> new GenreNotExistException(genreId));
+        this.genreLikesRepository.save(new UserGenres(genre, user));
+    }
+
+    @Override
+    public void unlikeGenre(Integer genreId, Integer userId) {
+        UserGenresPK movieLikesPK = new UserGenresPK(userId, genreId);
+        this.genreLikesRepository.deleteById(movieLikesPK);
+    }
 }
Index: src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -76,4 +76,9 @@
 
     @Override
+    public List<Integer> listAllIds() {
+        return this.movieRepository.findAllMovieIds();
+    }
+
+    @Override
     @Transactional
     public Movie save(String title, String description, String imageUrl,
Index: src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/service/impl/PersonServiceImpl.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -9,10 +9,6 @@
 import com.wediscussmovies.project.model.primarykeys.PersonRatesPK;
 import com.wediscussmovies.project.model.relation.MovieActors;
-import com.wediscussmovies.project.model.relation.MovieRates;
 import com.wediscussmovies.project.model.relation.PersonRates;
-import com.wediscussmovies.project.repository.MovieActorsRepository;
-import com.wediscussmovies.project.repository.MovieRepository;
-import com.wediscussmovies.project.repository.PersonRatesRepository;
-import com.wediscussmovies.project.repository.PersonRepository;
+import com.wediscussmovies.project.repository.*;
 import com.wediscussmovies.project.model.Person;
 import com.wediscussmovies.project.service.PersonService;
@@ -32,5 +28,4 @@
     private final MovieActorsRepository movieActorsRepository;
     private final PersonRatesRepository personRatesRepository;
-
 
     public PersonServiceImpl(PersonRepository personRepository,
@@ -156,4 +151,6 @@
 
 
+
+
     private void addActorForMovies(Person person, List<Integer> movieIds){
 
Index: src/main/java/com/wediscussmovies/project/web/PageFrontMovies.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/PageFrontMovies.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
+++ src/main/java/com/wediscussmovies/project/web/PageFrontMovies.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -0,0 +1,39 @@
+package com.wediscussmovies.project.web;
+
+import com.wediscussmovies.project.model.Movie;
+import com.wediscussmovies.project.service.MovieService;
+import org.springframework.ui.Model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PageFrontMovies {
+    public static List<Movie> getPagedMovies(String page, MovieService movieService, Model model){
+        List<Integer> movieIds = movieService.listAllIds();
+        List<Movie> movies = new ArrayList<>();
+        if(page==null || Integer.parseInt(page) <= 0)
+            page="1";
+        int pageToLoad = Integer.parseInt(page);
+
+        int from = (pageToLoad-1)*12;
+        int to = pageToLoad*12;
+
+        if (from>movieIds.size()){
+            page = "1";
+            pageToLoad = Integer.parseInt(page);
+            from = (pageToLoad-1)*12;
+            to = pageToLoad*12;
+        }
+        else if(to>movieIds.size()){
+            to = movieIds.size();
+        }
+
+        movieIds = movieIds.subList(from, to);
+
+        for(Integer id: movieIds){
+            movies.add(movieService.findById(id));
+        }
+        model.addAttribute("page", page);
+        return movies;
+    }
+}
Index: src/main/java/com/wediscussmovies/project/web/controller/GenreController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/GenreController.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/web/controller/GenreController.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -1,4 +1,10 @@
 package com.wediscussmovies.project.web.controller;
 
+import com.wediscussmovies.project.LoggedUser;
+import com.wediscussmovies.project.model.Genre;
+import com.wediscussmovies.project.model.User;
+import com.wediscussmovies.project.model.relation.UserGenres;
+import com.wediscussmovies.project.querymodels.GenreLikes;
+import com.wediscussmovies.project.repository.GenreLikesRepository;
 import com.wediscussmovies.project.service.GenreService;
 import org.springframework.stereotype.Controller;
@@ -7,17 +13,35 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @Controller
 @RequestMapping("/genres")
 public class GenreController {
     private final GenreService genreService;
+    private final GenreLikesRepository genreLikesRepository;
 
-    public GenreController(GenreService genreService) {
+    public GenreController(GenreService genreService, GenreLikesRepository genreLikesRepository) {
         this.genreService = genreService;
+        this.genreLikesRepository = genreLikesRepository;
     }
     @GetMapping
     public String getGenres(Model model){
         model.addAttribute("genres",genreService.findAllWithLikes());
+        model.addAttribute("allGenres", genreService.findAll());
         model.addAttribute("contentTemplate","genres");
+        addModelPropertiesForUser(model);
         return "template";
     }
+
+    private void addModelPropertiesForUser(Model model){
+        User user = LoggedUser.getLoggedUser();
+        List<UserGenres> genreLikesList = this.genreLikesRepository.findAllByUser(user);
+        List<Genre> genres = new ArrayList<>();
+        for(UserGenres g: genreLikesList){
+            genres.add(genreService.findById(g.getId().getGenreId()));
+        }
+        model.addAttribute("likedGenres",genres);
+        model.addAttribute("user",user);
+    }
 }
Index: src/main/java/com/wediscussmovies/project/web/controller/MovieController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/MovieController.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/web/controller/MovieController.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -9,4 +9,5 @@
 import com.wediscussmovies.project.service.PersonService;
 import com.wediscussmovies.project.web.DesignFrontMovies;
+import com.wediscussmovies.project.web.PageFrontMovies;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
@@ -37,5 +38,5 @@
     }
 
-    @GetMapping
+    @GetMapping("/old")
     public String getMovies(@RequestParam(required = false) String titleQuery, Model model,
                             @RequestParam(required = false) String error){
@@ -55,4 +56,23 @@
         model.addAttribute("movie_rows", movie_rows);
         model.addAttribute("contentTemplate", "moviesList");
+        if (error != null && !error.equals(" "))
+            model.addAttribute("error",error);
+        return "template";
+    }
+
+
+    @GetMapping
+    public String getMoviesAlternative(@RequestParam(required = false) String titleQuery, Model model,
+                            @RequestParam(required = false) String error, @RequestParam(required = false) String page){
+        if (page==null){
+            return "redirect:/movies?page=1";
+        }
+        addModelPropertiesForUser(model);
+        List<Movie> movies = PageFrontMovies.getPagedMovies(page, movieService, model);
+        List<List<Movie>> movie_rows = new ArrayList<>();
+        DesignFrontMovies.designMovieList(movies,movie_rows);
+        model.addAttribute("movies", movies);
+        model.addAttribute("movie_rows", movie_rows);
+        model.addAttribute("contentTemplate", "moviesListPaged");
         if (error != null && !error.equals(" "))
             model.addAttribute("error",error);
@@ -160,6 +180,5 @@
     }
     private void addModelProperties(Model model){
-
-        model.addAttribute("directors",  personService.findAllDirectors());
+        model.addAttribute("directors", personService.findAllDirectors());
         model.addAttribute("actors", personService.findAllActors());
         model.addAttribute("genres", genreService.findAll());
@@ -169,5 +188,5 @@
         model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
         model.addAttribute("user",user);
-        }
+    }
 
 }
Index: src/main/java/com/wediscussmovies/project/web/controller/PersonController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/PersonController.java	(revision 7f3655122036717700124fc482399ad0780bdf52)
+++ src/main/java/com/wediscussmovies/project/web/controller/PersonController.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -1,5 +1,7 @@
 package com.wediscussmovies.project.web.controller;
 
+import com.wediscussmovies.project.LoggedUser;
 import com.wediscussmovies.project.model.Person;
+import com.wediscussmovies.project.model.User;
 import com.wediscussmovies.project.service.MovieService;
 import com.wediscussmovies.project.service.PersonService;
@@ -135,4 +137,9 @@
     }
 
+    private void addModelPropertiesForUser(Model model){
+        User user = LoggedUser.getLoggedUser();
+        model.addAttribute("user",user);
+    }
+
 
 }
Index: src/main/java/com/wediscussmovies/project/web/controller/rest/GenreRestController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/rest/GenreRestController.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
+++ src/main/java/com/wediscussmovies/project/web/controller/rest/GenreRestController.java	(revision ad4243e9a9e46a065706d093b2c5200c02d2d78e)
@@ -0,0 +1,38 @@
+package com.wediscussmovies.project.web.controller.rest;
+
+import com.wediscussmovies.project.service.DiscussionService;
+import com.wediscussmovies.project.service.GenreService;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("api/genres")
+public class GenreRestController {
+    private final GenreService genreService;
+
+    public GenreRestController(GenreService genreService) {
+        this.genreService = genreService;
+    }
+
+    @GetMapping("/like/{genreId}")
+    public ResponseEntity likeGenre(@PathVariable Integer genreId, @RequestParam Integer userId){
+        try {
+            this.genreService.likeGenre(genreId,userId);
+            return ResponseEntity.ok(true);
+        }
+        catch (RuntimeException exception){
+            return ResponseEntity.ok(false);
+        }
+    }
+    @GetMapping("/unlike/{genreId}")
+    public ResponseEntity unlikeGenre (@PathVariable Integer genreId, @RequestParam Integer userId){
+        try {
+            this.genreService.unlikeGenre(genreId,userId);
+            return ResponseEntity.ok(true);
+        }
+        catch (RuntimeException exception){
+            System.out.println(exception.getMessage());
+            return ResponseEntity.ok(false);
+        }
+    }
+}
