Changeset 6f91f99 in Git for src/main/java/com/wediscussmovies
- Timestamp:
- 02/09/22 15:46:58 (3 years ago)
- Branches:
- main
- Children:
- 8f1b7e9
- Parents:
- 967b414
- Location:
- src/main/java/com/wediscussmovies/project
- Files:
-
- 12 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/model/Discussion.java
r967b414 r6f91f99 1 1 package com.wediscussmovies.project.model; 2 2 3 import com.wediscussmovies.project.model.relation.DiscussionLikes; 3 4 import lombok.Data; 4 5 5 6 import javax.persistence.*; 6 7 import java.sql.Date; 8 import java.util.List; 7 9 import java.util.Objects; 8 10 … … 29 31 30 32 33 34 35 31 36 @ManyToOne 32 37 @JoinColumn(name = "movie_id") … … 41 46 private Person person; 42 47 48 @Transient 49 private Long likes; 50 43 51 public Discussion(Character type, String text, String title, Date date, User user) { 44 52 this.type = type; … … 52 60 } 53 61 54 public String getText() {55 return text;56 }57 58 public void setText(String text) {59 this.text = text;60 }61 62 public String getTitle() {63 return title;64 }65 66 public void setTitle(String title) {67 this.title = title;68 }69 70 public Date getDate() {71 return date;72 }73 74 public void setDate(Date date) {75 this.date = date;76 }77 62 78 63 @Override -
src/main/java/com/wediscussmovies/project/querymodels/DiscussionLikesQM.java
r967b414 r6f91f99 6 6 7 7 @Data 8 public class DiscussionLikes {8 public class DiscussionLikesQM { 9 9 private Integer discussionId; 10 10 private Long likes; 11 11 12 public DiscussionLikes (Integer discussionId, Long likes) {12 public DiscussionLikesQM(Integer discussionId, Long likes) { 13 13 this.discussionId = discussionId; 14 14 this.likes = likes; 15 15 } 16 16 17 public DiscussionLikes () {17 public DiscussionLikesQM() { 18 18 } 19 19 … … 22 22 if (this == o) return true; 23 23 if (o == null || getClass() != o.getClass()) return false; 24 DiscussionLikes that = (DiscussionLikes) o;24 DiscussionLikesQM that = (DiscussionLikesQM) o; 25 25 return Objects.equals(discussionId, that.discussionId) && Objects.equals(likes, that.likes); 26 26 } -
src/main/java/com/wediscussmovies/project/querymodels/GenreLikesQM.java
r967b414 r6f91f99 3 3 import lombok.Data; 4 4 5 import javax.persistence.Entity;6 import javax.persistence.Table;7 import java.util.Comparator;8 5 import java.util.Objects; 9 6 10 7 @Data 11 public class GenreLikes {8 public class GenreLikesQM { 12 9 private Integer genreId; 13 10 private String name; 14 11 private Long likes; 15 12 16 public static Comparator<GenreLikes> sorter = Comparator.comparing(GenreLikes::getLikes).thenComparing(GenreLikes::getName).reversed();13 //public static Comparator<GenreLikes> sorter = Comparator.comparing(GenreLikes::getLikes).thenComparing(GenreLikes::getName).reversed(); 17 14 18 public GenreLikes (Integer genreId, String name, Long likes) {15 public GenreLikesQM(Integer genreId, String name, Long likes) { 19 16 this.genreId = genreId; 20 17 this.name = name; … … 27 24 if (this == o) return true; 28 25 if (o == null || getClass() != o.getClass()) return false; 29 GenreLikes that = (GenreLikes) o;26 GenreLikesQM that = (GenreLikesQM) o; 30 27 return Objects.equals(genreId, that.genreId); 31 28 } -
src/main/java/com/wediscussmovies/project/repository/DiscussionLikesRepository.java
r967b414 r6f91f99 7 7 import com.wediscussmovies.project.model.relation.MovieLikes; 8 8 import com.wediscussmovies.project.model.relation.UserGenres; 9 import org.springframework.data.domain.Sort; 9 10 import org.springframework.data.jpa.repository.JpaRepository; 10 11 import org.springframework.stereotype.Repository; … … 15 16 public interface DiscussionLikesRepository extends JpaRepository<DiscussionLikes, DiscussionLikesPK> { 16 17 List<DiscussionLikes> findAllByUser(User user); 18 17 19 } -
src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java
r967b414 r6f91f99 4 4 import com.wediscussmovies.project.model.Movie; 5 5 import com.wediscussmovies.project.model.Person; 6 import com.wediscussmovies.project.querymodels.DiscussionLikes; 7 import com.wediscussmovies.project.querymodels.GenreLikes; 6 import com.wediscussmovies.project.querymodels.DiscussionLikesQM; 8 7 import org.springframework.data.jpa.repository.JpaRepository; 9 8 import org.springframework.data.jpa.repository.Query; 9 import org.springframework.data.repository.query.Param; 10 10 import org.springframework.stereotype.Repository; 11 11 … … 19 19 List<Discussion> findAllByPerson (Person person); 20 20 21 @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikes (d.discussionId, count(dl.id.userId)) from Discussion d" +21 @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikesQM(d.discussionId, count(dl.id.userId)) from Discussion d" + 22 22 " left join DiscussionLikes dl on dl.id.discussionId = d.discussionId" + 23 " group by d.discussionId" + 23 " where :discussionId = d.discussionId" + 24 " group by d.discussionId"+ 24 25 " order by count(dl.id.userId) desc") 25 26 @Transactional 26 List<DiscussionLikes> findAllWithLikes(); 27 DiscussionLikesQM findDiscussionWithLikes(@Param("discussionId") Integer discussionId); 28 29 @Query(value = "select new com.wediscussmovies.project.querymodels.DiscussionLikesQM(d.discussionId, count(dl.id.userId)) from Discussion d" + 30 " left join DiscussionLikes dl on dl.id.discussionId = d.discussionId" + 31 " group by d.discussionId"+ 32 " order by count(dl.id.userId) desc") 33 @Transactional 34 List<DiscussionLikesQM> findAllDiscussionsWithLikes(); 27 35 } -
src/main/java/com/wediscussmovies/project/repository/GenreLikesRepository.java
r967b414 r6f91f99 2 2 3 3 import com.wediscussmovies.project.model.User; 4 import com.wediscussmovies.project.model.primarykeys.GenreLikesPK;5 import com.wediscussmovies.project.model.primarykeys.MovieLikesPK;6 4 import com.wediscussmovies.project.model.primarykeys.UserGenresPK; 7 import com.wediscussmovies.project.model.relation.MovieLikes;8 5 import com.wediscussmovies.project.model.relation.UserGenres; 9 import com.wediscussmovies.project.querymodels.GenreLikes;10 6 import org.springframework.data.jpa.repository.JpaRepository; 11 7 import org.springframework.stereotype.Repository; -
src/main/java/com/wediscussmovies/project/repository/GenreRepository.java
r967b414 r6f91f99 2 2 3 3 import com.wediscussmovies.project.model.Genre; 4 import com.wediscussmovies.project.querymodels.GenreLikes ;4 import com.wediscussmovies.project.querymodels.GenreLikesQM; 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 6 import org.springframework.data.jpa.repository.Modifying; … … 10 10 11 11 import javax.transaction.Transactional; 12 import java.sql.Date;13 12 import java.util.List; 14 13 … … 17 16 List<Genre> findAllByGenreType(String genre); 18 17 19 @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikes (g.genreId, g.genreType, count(ug.id.userId)) from Genre g" +18 @Query(value = "select new com.wediscussmovies.project.querymodels.GenreLikesQM(g.genreId, g.genreType, count(ug.id.userId)) from Genre g" + 20 19 " left join UserGenres ug on ug.id.genreId = g.genreId" + 21 20 " group by g.genreId, g.genreType" + 22 " order by count(ug.id.userId) desc ")21 " order by count(ug.id.userId) desc, g.genreType asc") 23 22 @Transactional 24 List<GenreLikes > findAllWithLikes();23 List<GenreLikesQM> findAllWithLikes(); 25 24 26 25 @Modifying -
src/main/java/com/wediscussmovies/project/repository/MovieRepository.java
r967b414 r6f91f99 3 3 import com.wediscussmovies.project.model.Movie; 4 4 import com.wediscussmovies.project.model.Person; 5 import com.wediscussmovies.project.querymodels.GenreLikes;6 5 import com.wediscussmovies.project.querymodels.MovieLikesQM; 7 6 import org.springframework.data.jpa.repository.JpaRepository; -
src/main/java/com/wediscussmovies/project/service/DiscussionService.java
r967b414 r6f91f99 3 3 import com.wediscussmovies.project.model.Discussion; 4 4 import com.wediscussmovies.project.model.User; 5 import com.wediscussmovies.project.querymodels.DiscussionLikes ;5 import com.wediscussmovies.project.querymodels.DiscussionLikesQM; 6 6 7 7 import java.util.List; … … 20 20 List<Discussion> findLikedDiscussionsByUser(User user); 21 21 22 DiscussionLikes findLikesForDiscussionWithId(int discussionId); 22 DiscussionLikesQM findLikesForDiscussionWithId(Integer discussionId); 23 24 void findLikesForAllDiscussions(List<Discussion> discussions); 23 25 24 26 } -
src/main/java/com/wediscussmovies/project/service/GenreService.java
r967b414 r6f91f99 2 2 3 3 import com.wediscussmovies.project.model.Genre; 4 import com.wediscussmovies.project.querymodels.GenreLikes ;4 import com.wediscussmovies.project.querymodels.GenreLikesQM; 5 5 import org.springframework.stereotype.Service; 6 6 … … 13 13 List<Genre> findAllByType(String genre); 14 14 Genre save(String genreName); 15 List<GenreLikes > findAllWithLikes();15 List<GenreLikesQM> findAllWithLikes(); 16 16 void likeGenre(Integer genreId,Integer userId); 17 17 void unlikeGenre(Integer genreId,Integer userId); -
src/main/java/com/wediscussmovies/project/service/impl/DiscussionServiceImpl.java
r967b414 r6f91f99 7 7 import com.wediscussmovies.project.model.primarykeys.DiscussionLikesPK; 8 8 import com.wediscussmovies.project.model.relation.DiscussionLikes; 9 import com.wediscussmovies.project.querymodels.DiscussionLikesQM; 9 10 import com.wediscussmovies.project.repository.*; 10 11 import com.wediscussmovies.project.model.Discussion; … … 115 116 116 117 @Override 117 public com.wediscussmovies.project.querymodels.DiscussionLikes findLikesForDiscussionWithId(int discussionId) { 118 return discussionRepository.findAllWithLikes().stream().filter(d -> d.getDiscussionId().equals(discussionId)).findFirst().get(); 118 public DiscussionLikesQM findLikesForDiscussionWithId(Integer discussionId) { 119 // return discussionRepository.findAllWithLikes().stream().filter(d -> d.getDiscussionId().equals(discussionId)).findFirst().get(); 120 return this.discussionRepository.findDiscussionWithLikes(discussionId); 121 122 } 123 124 @Override 125 public void findLikesForAllDiscussions(List<Discussion> discussions) { 126 // this.discussionRepository.findAllDiscussionsWithLikes() 127 // .forEach(el ->{ 128 // if (discussions.) 129 // }); 119 130 } 120 131 -
src/main/java/com/wediscussmovies/project/service/impl/GenreServiceImpl.java
r967b414 r6f91f99 4 4 import com.wediscussmovies.project.model.exception.GenreNotExistException; 5 5 import com.wediscussmovies.project.model.exception.UserNotExistException; 6 import com.wediscussmovies.project.model.primarykeys.GenreLikesPK;7 6 import com.wediscussmovies.project.model.primarykeys.UserGenresPK; 8 import com.wediscussmovies.project.model.relation.MovieLikes;9 7 import com.wediscussmovies.project.model.relation.UserGenres; 10 import com.wediscussmovies.project.querymodels.GenreLikes ;8 import com.wediscussmovies.project.querymodels.GenreLikesQM; 11 9 import com.wediscussmovies.project.repository.GenreLikesRepository; 12 10 import com.wediscussmovies.project.repository.GenreRepository; … … 48 46 49 47 @Override 50 public List<GenreLikes > findAllWithLikes() {51 List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes();52 genreLikesList.sort(GenreLikes.sorter);53 return genreLikesList;48 public List<GenreLikesQM> findAllWithLikes() { 49 // List<GenreLikes> genreLikesList = this.genreRepository.findAllWithLikes(); 50 // genreLikesList.sort(GenreLikes.sorter); 51 return this.genreRepository.findAllWithLikes(); 54 52 } 55 53 -
src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java
r967b414 r6f91f99 6 6 import com.wediscussmovies.project.model.User; 7 7 import com.wediscussmovies.project.model.relation.DiscussionLikes; 8 import com.wediscussmovies.project.querymodels.DiscussionLikesQM; 8 9 import com.wediscussmovies.project.service.DiscussionService; 9 10 import com.wediscussmovies.project.service.MovieService; … … 62 63 try { 63 64 Discussion disc = discussionService.findById(id); 65 disc.setLikes(discussionService.findLikesForDiscussionWithId(disc.getDiscussionId()).getLikes()); 64 66 model.addAttribute("disc", disc); 65 67 model.addAttribute("contentTemplate", "discussion"); 66 model.addAttribute("user",LoggedUser.getLoggedUser());67 68 model.addAttribute("replies",this.replyService.findAllByDiscussion(disc)); 68 addModelPropertiesLikes(model, disc, null);69 69 addModelPropertiesForUser(model); 70 70 … … 183 183 } 184 184 private void addModelPropertiesLikes(Model model, Discussion discussion, List<Discussion> discussions){ 185 // ispagja kompliciran kod vaka, podobro da dodademe i svojstvo u diskusijata i koga ke se dodade lajk 186 // soodvetno da se zgoleme i obratno 185 187 if(discussion==null){ 186 List< com.wediscussmovies.project.querymodels.DiscussionLikes> discussionLikes = new ArrayList<>();188 List<DiscussionLikesQM> discussionLikes = new ArrayList<>(); 187 189 for(Discussion d: discussions){ 188 190 discussionLikes.add(discussionService.findLikesForDiscussionWithId(d.getDiscussionId())); -
src/main/java/com/wediscussmovies/project/web/controller/GenreController.java
r967b414 r6f91f99 5 5 import com.wediscussmovies.project.model.User; 6 6 import com.wediscussmovies.project.model.relation.UserGenres; 7 import com.wediscussmovies.project.querymodels.GenreLikes;8 7 import com.wediscussmovies.project.repository.GenreLikesRepository; 9 8 import com.wediscussmovies.project.service.GenreService;
Note:
See TracChangeset
for help on using the changeset viewer.