Index: src/main/java/com/wediscussmovies/project/model/Discussion.java
===================================================================
--- src/main/java/com/wediscussmovies/project/model/Discussion.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/model/Discussion.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -1,8 +1,10 @@
 package com.wediscussmovies.project.model;
 
+import com.wediscussmovies.project.model.relation.DiscussionLikes;
 import lombok.Data;
 
 import javax.persistence.*;
 import java.sql.Date;
+import java.util.List;
 import java.util.Objects;
 
@@ -29,4 +31,7 @@
 
 
+
+
+
     @ManyToOne
     @JoinColumn(name = "movie_id")
@@ -41,4 +46,7 @@
     private Person person;
 
+    @Transient
+    private Long likes;
+
     public Discussion(Character type, String text, String title, Date date, User user) {
         this.type = type;
@@ -52,27 +60,4 @@
     }
 
-    public String getText() {
-        return text;
-    }
-
-    public void setText(String text) {
-        this.text = text;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public void setDate(Date date) {
-        this.date = date;
-    }
 
     @Override
Index: src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikes.java
===================================================================
--- src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikes.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ 	(revision )
@@ -1,32 +1,0 @@
-package com.wediscussmovies.project.querymodels;
-
-import lombok.Data;
-
-import java.util.Objects;
-
-@Data
-public class DiscussionLikes {
-    private Integer discussionId;
-    private Long likes;
-
-    public DiscussionLikes(Integer discussionId, Long likes) {
-        this.discussionId = discussionId;
-        this.likes = likes;
-    }
-
-    public DiscussionLikes() {
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        DiscussionLikes that = (DiscussionLikes) o;
-        return Objects.equals(discussionId, that.discussionId) && Objects.equals(likes, that.likes);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(discussionId, likes);
-    }
-}
Index: src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikesQM.java
===================================================================
--- src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikesQM.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
+++ src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikesQM.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -0,0 +1,32 @@
+package com.wediscussmovies.project.querymodels;
+
+import lombok.Data;
+
+import java.util.Objects;
+
+@Data
+public class DiscussionLikesQM {
+    private Integer discussionId;
+    private Long likes;
+
+    public DiscussionLikesQM(Integer discussionId, Long likes) {
+        this.discussionId = discussionId;
+        this.likes = likes;
+    }
+
+    public DiscussionLikesQM() {
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        DiscussionLikesQM that = (DiscussionLikesQM) o;
+        return Objects.equals(discussionId, that.discussionId) && Objects.equals(likes, that.likes);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(discussionId, likes);
+    }
+}
Index: src/main/java/com/wediscussmovies/project/querymodels/GenreLikes.java
===================================================================
--- src/main/java/com/wediscussmovies/project/querymodels/GenreLikes.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ 	(revision )
@@ -1,37 +1,0 @@
-package com.wediscussmovies.project.querymodels;
-
-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 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/querymodels/GenreLikesQM.java
===================================================================
--- src/main/java/com/wediscussmovies/project/querymodels/GenreLikesQM.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
+++ src/main/java/com/wediscussmovies/project/querymodels/GenreLikesQM.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -0,0 +1,34 @@
+package com.wediscussmovies.project.querymodels;
+
+import lombok.Data;
+
+import java.util.Objects;
+
+@Data
+public class GenreLikesQM {
+    private Integer genreId;
+    private String name;
+    private Long likes;
+
+    //public static Comparator<GenreLikes> sorter = Comparator.comparing(GenreLikes::getLikes).thenComparing(GenreLikes::getName).reversed();
+
+    public GenreLikesQM(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;
+        GenreLikesQM that = (GenreLikesQM) o;
+        return Objects.equals(genreId, that.genreId);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(genreId);
+    }
+}
Index: src/main/java/com/wediscussmovies/project/repository/DiscussionLikesRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/DiscussionLikesRepository.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/repository/DiscussionLikesRepository.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -7,4 +7,5 @@
 import com.wediscussmovies.project.model.relation.MovieLikes;
 import com.wediscussmovies.project.model.relation.UserGenres;
+import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
@@ -15,3 +16,4 @@
 public interface DiscussionLikesRepository extends JpaRepository<DiscussionLikes, DiscussionLikesPK> {
     List<DiscussionLikes> findAllByUser(User user);
+
 }
Index: src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -4,8 +4,8 @@
 import com.wediscussmovies.project.model.Movie;
 import com.wediscussmovies.project.model.Person;
-import com.wediscussmovies.project.querymodels.DiscussionLikes;
-import com.wediscussmovies.project.querymodels.GenreLikes;
+import com.wediscussmovies.project.querymodels.DiscussionLikesQM;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
@@ -19,9 +19,17 @@
      List<Discussion> findAllByPerson (Person person);
 
-     @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikes(d.discussionId, count(dl.id.userId)) from Discussion d" +
+     @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikesQM(d.discussionId, count(dl.id.userId)) from Discussion d" +
              " left join DiscussionLikes dl on dl.id.discussionId = d.discussionId" +
-             " group by d.discussionId" +
+             " where :discussionId = d.discussionId" +
+             " group by d.discussionId"+
              " order by count(dl.id.userId) desc")
      @Transactional
-     List<DiscussionLikes> findAllWithLikes();
+     DiscussionLikesQM findDiscussionWithLikes(@Param("discussionId") Integer discussionId);
+
+     @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikesQM(d.discussionId, count(dl.id.userId)) from Discussion d" +
+             " left join DiscussionLikes dl on dl.id.discussionId = d.discussionId" +
+             " group by d.discussionId"+
+             " order by count(dl.id.userId) desc")
+     @Transactional
+     List<DiscussionLikesQM> findAllDiscussionsWithLikes();
 }
Index: src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -2,10 +2,6 @@
 
 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;
Index: src/main/java/com/wediscussmovies/project/repository/GenreRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/GenreRepository.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/repository/GenreRepository.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -2,5 +2,5 @@
 
 import com.wediscussmovies.project.model.Genre;
-import com.wediscussmovies.project.querymodels.GenreLikes;
+import com.wediscussmovies.project.querymodels.GenreLikesQM;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
@@ -10,5 +10,4 @@
 
 import javax.transaction.Transactional;
-import java.sql.Date;
 import java.util.List;
 
@@ -17,10 +16,10 @@
      List<Genre> findAllByGenreType(String genre);
 
-     @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikes(g.genreId, g.genreType, count(ug.id.userId)) from Genre g" +
+     @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikesQM(g.genreId, g.genreType, count(ug.id.userId)) from Genre g" +
              " left join UserGenres ug on ug.id.genreId = g.genreId" +
              " group by g.genreId, g.genreType" +
-             " order by count(ug.id.userId) desc")
+             " order by count(ug.id.userId) desc, g.genreType asc")
      @Transactional
-     List<GenreLikes> findAllWithLikes();
+     List<GenreLikesQM> findAllWithLikes();
 
      @Modifying
Index: src/main/java/com/wediscussmovies/project/repository/MovieRepository.java
===================================================================
--- src/main/java/com/wediscussmovies/project/repository/MovieRepository.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/repository/MovieRepository.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -3,5 +3,4 @@
 import com.wediscussmovies.project.model.Movie;
 import com.wediscussmovies.project.model.Person;
-import com.wediscussmovies.project.querymodels.GenreLikes;
 import com.wediscussmovies.project.querymodels.MovieLikesQM;
 import org.springframework.data.jpa.repository.JpaRepository;
Index: src/main/java/com/wediscussmovies/project/service/DiscussionService.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/DiscussionService.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/service/DiscussionService.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -3,5 +3,5 @@
 import com.wediscussmovies.project.model.Discussion;
 import com.wediscussmovies.project.model.User;
-import com.wediscussmovies.project.querymodels.DiscussionLikes;
+import com.wediscussmovies.project.querymodels.DiscussionLikesQM;
 
 import java.util.List;
@@ -20,5 +20,7 @@
     List<Discussion> findLikedDiscussionsByUser(User user);
 
-    DiscussionLikes findLikesForDiscussionWithId(int discussionId);
+    DiscussionLikesQM findLikesForDiscussionWithId(Integer discussionId);
+
+    void findLikesForAllDiscussions(List<Discussion> discussions);
 
 }
Index: src/main/java/com/wediscussmovies/project/service/GenreService.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/GenreService.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/service/GenreService.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -2,5 +2,5 @@
 
 import com.wediscussmovies.project.model.Genre;
-import com.wediscussmovies.project.querymodels.GenreLikes;
+import com.wediscussmovies.project.querymodels.GenreLikesQM;
 import org.springframework.stereotype.Service;
 
@@ -13,5 +13,5 @@
     List<Genre> findAllByType(String genre);
     Genre save(String genreName);
-    List<GenreLikes> findAllWithLikes();
+    List<GenreLikesQM> findAllWithLikes();
     void likeGenre(Integer genreId,Integer userId);
     void unlikeGenre(Integer genreId,Integer userId);
Index: src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -7,4 +7,5 @@
 import com.wediscussmovies.project.model.primarykeys.DiscussionLikesPK;
 import com.wediscussmovies.project.model.relation.DiscussionLikes;
+import com.wediscussmovies.project.querymodels.DiscussionLikesQM;
 import com.wediscussmovies.project.repository.*;
 import com.wediscussmovies.project.model.Discussion;
@@ -115,6 +116,16 @@
 
     @Override
-    public com.wediscussmovies.project.querymodels.DiscussionLikes findLikesForDiscussionWithId(int discussionId) {
-        return discussionRepository.findAllWithLikes().stream().filter(d ->  d.getDiscussionId().equals(discussionId)).findFirst().get();
+    public DiscussionLikesQM findLikesForDiscussionWithId(Integer discussionId) {
+//        return discussionRepository.findAllWithLikes().stream().filter(d ->  d.getDiscussionId().equals(discussionId)).findFirst().get();
+                return this.discussionRepository.findDiscussionWithLikes(discussionId);
+
+    }
+
+    @Override
+    public void findLikesForAllDiscussions(List<Discussion> discussions) {
+//        this.discussionRepository.findAllDiscussionsWithLikes()
+//                .forEach(el ->{
+//                        if (discussions.)
+//                });
     }
 
Index: src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
===================================================================
--- src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -4,9 +4,7 @@
 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.querymodels.GenreLikesQM;
 import com.wediscussmovies.project.repository.GenreLikesRepository;
 import com.wediscussmovies.project.repository.GenreRepository;
@@ -48,8 +46,8 @@
 
     @Override
-    public List<GenreLikes> findAllWithLikes() {
-        List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes();
-        genreLikesList.sort(GenreLikes.sorter);
-        return genreLikesList;
+    public List<GenreLikesQM> findAllWithLikes() {
+        // List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes();
+       // genreLikesList.sort(GenreLikes.sorter);
+        return this.genreRepository.findAllWithLikes();
     }
 
Index: src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -6,4 +6,5 @@
 import com.wediscussmovies.project.model.User;
 import com.wediscussmovies.project.model.relation.DiscussionLikes;
+import com.wediscussmovies.project.querymodels.DiscussionLikesQM;
 import com.wediscussmovies.project.service.DiscussionService;
 import com.wediscussmovies.project.service.MovieService;
@@ -62,9 +63,8 @@
         try {
             Discussion disc = discussionService.findById(id);
+            disc.setLikes(discussionService.findLikesForDiscussionWithId(disc.getDiscussionId()).getLikes());
             model.addAttribute("disc", disc);
             model.addAttribute("contentTemplate", "discussion");
-            model.addAttribute("user",LoggedUser.getLoggedUser());
             model.addAttribute("replies",this.replyService.findAllByDiscussion(disc));
-            addModelPropertiesLikes(model, disc, null);
             addModelPropertiesForUser(model);
 
@@ -183,6 +183,8 @@
     }
     private void addModelPropertiesLikes(Model model, Discussion discussion, List<Discussion> discussions){
+        // ispagja kompliciran kod vaka, podobro da dodademe i svojstvo u diskusijata i koga ke se dodade lajk
+        // soodvetno da se zgoleme i obratno
         if(discussion==null){
-            List<com.wediscussmovies.project.querymodels.DiscussionLikes> discussionLikes = new ArrayList<>();
+            List<DiscussionLikesQM> discussionLikes = new ArrayList<>();
             for(Discussion d: discussions){
                 discussionLikes.add(discussionService.findLikesForDiscussionWithId(d.getDiscussionId()));
Index: src/main/java/com/wediscussmovies/project/web/controller/GenreController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/GenreController.java	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/java/com/wediscussmovies/project/web/controller/GenreController.java	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -5,5 +5,4 @@
 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;
Index: src/main/resources/static/js/sharedScript.js
===================================================================
--- src/main/resources/static/js/sharedScript.js	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/resources/static/js/sharedScript.js	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -91,6 +91,6 @@
 
     $(".user-movies-list").on("click", function (){
-        children = $(this).children()
-        first = true
+       let children = $(this).children()
+        let first = true
         for (let item of children){
             if(first){
Index: src/main/resources/templates/discussionsList.html
===================================================================
--- src/main/resources/templates/discussionsList.html	(revision 3fe36de5813c3dc0a535a893e180e3b45bfb1430)
+++ src/main/resources/templates/discussionsList.html	(revision 6f91f99177aa46ee208fa8328553bb98a196cc3a)
@@ -31,5 +31,5 @@
                                 <a th:text="${disc.getTitle()}" th:href="@{'/discussions/{id}' (id=${disc.getDiscussionId()})}"></a>
                             </td>
-                            <td th:each="like : ${likes}" th:if="${like.getDiscussionId().equals(disc.getDiscussionId())}" th:text="${like.getLikes()}" class="likes_count">
+                            <td th:text="${disc.getLikes()}" class="likes_count">
                             </td>
                             <td th:text="${disc.getDate()}"></td>
@@ -41,6 +41,6 @@
                             <td th:if="${!disc.getUser().equals(user)}"><a class="btn btn-success" th:href="@{'/replies/add/{discussionId}' (discussionId=${disc.getDiscussionId()})}">Реплицирај</a> </td>
                             <td th:if="${!disc.getUser().equals(user)}">
-                                <a class='btn btn-success button-like-discussion-alt' th:if="${!likedDiscussions.contains(disc)}" th:discussion-id="${disc.getDiscussionId()}" th:user-id="${user.getUserId()}" >❤</a>
-                                <a class='btn btn-danger button-unlike-discussion-alt' th:if="${likedDiscussions.contains(disc)}" th:discussion-id="${disc.getDiscussionId()}" th:user-id="${user.getUserId()}" >💔</a>
+                                <a class='btn btn-success button-like-discussion-alt' th:if="${!likedDiscussions.contains(disc)}" th:discussion-id="${disc?.getDiscussionId()}" th:user-id="${user.getUserId()}" >❤</a>
+                                <a class='btn btn-danger button-unlike-discussion-alt' th:if="${likedDiscussions.contains(disc)}" th:discussion-id="${disc?.getDiscussionId()}" th:user-id="${user.getUserId()}" >💔</a>
                             </td>
                             </th:block>
