-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...in/java/core/application/movies/repositories/comment/jpa/JpaCommentDislikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package core.application.movies.repositories.comment.jpa; | ||
|
||
import core.application.movies.models.entities.CommentDislike; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface JpaCommentDislikeRepository extends JpaRepository<CommentDislike, Long> { | ||
|
||
@Modifying | ||
@Query(value = "insert into comment_dislike_table(comment_id, user_id) values (:commentId, :userId)", nativeQuery = true) | ||
void saveDisLike(Long commentId, UUID userId); | ||
|
||
Boolean existsByComment_CommentIdAndUserId(Long commentId, UUID userId); | ||
|
||
void deleteByComment_CommentIdAndUserId(Long commentId, UUID userId); | ||
} |
19 changes: 19 additions & 0 deletions
19
.../main/java/core/application/movies/repositories/comment/jpa/JpaCommentLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core.application.movies.repositories.comment.jpa; | ||
|
||
import core.application.movies.models.entities.CommentLike; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface JpaCommentLikeRepository extends JpaRepository<CommentLike, Long> { | ||
|
||
@Modifying | ||
@Query(value = "insert into comment_like_table(comment_id, user_id) values (:commentId, :userId)", | ||
nativeQuery = true) | ||
void saveLike(Long commentId, UUID userId); | ||
|
||
Boolean existsByComment_CommentIdAndUserId(Long commentId, UUID userId); | ||
|
||
void deleteByComment_CommentIdAndUserId(Long commentId, UUID userId); | ||
} |
31 changes: 31 additions & 0 deletions
31
.../src/main/java/core/application/movies/repositories/comment/jpa/JpaCommentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package core.application.movies.repositories.comment.jpa; | ||
|
||
import core.application.movies.models.dto.response.CommentRespDTO; | ||
import core.application.movies.models.entities.CommentEntity; | ||
import java.util.UUID; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface JpaCommentRepository extends JpaRepository<CommentEntity, Long> { | ||
Boolean existsByMovieIdAndUserId(String movieId, UUID userId); | ||
|
||
@Query("SELECT new core.application.movies.models.dto.response.CommentRespDTO(c.commentId, c.content, c.like, c.dislike, c.rating, c.movieId, c.userId, c.createdAt, " + | ||
"CASE WHEN l.commentLikeId IS NOT NULL THEN true ELSE false END, " + | ||
"CASE WHEN d.commentDislikeId IS NOT NULL THEN true ELSE false END) " + | ||
"FROM CommentEntity c " + | ||
"LEFT JOIN CommentLike l ON c.commentId = l.comment.commentId AND l.userId = :userId " + | ||
"LEFT JOIN CommentDislike d ON c.commentId = d.comment.commentId AND d.userId = :userId " + | ||
"WHERE c.movieId = :movieId") | ||
Page<CommentRespDTO> findByMovieId(String movieId, UUID userId, Pageable pageable); | ||
|
||
@Query("SELECT new core.application.movies.models.dto.response.CommentRespDTO(c.commentId, c.content, c.like, c.dislike, c.rating, c.movieId, c.userId, c.createdAt, " + | ||
"CASE WHEN l.commentLikeId IS NOT NULL THEN true ELSE false END, " + | ||
"CASE WHEN d.commentDislikeId IS NOT NULL THEN true ELSE false END) " + | ||
"FROM CommentEntity c " + | ||
"LEFT JOIN CommentLike l ON c.commentId = l.comment.commentId AND l.userId = :userId " + | ||
"LEFT JOIN CommentDislike d ON c.commentId = d.comment.commentId AND d.userId = :userId " + | ||
"WHERE c.movieId = :movieId") | ||
Page<CommentRespDTO> findByMovieIdOrderBy(String movieId, UUID userId, Pageable pageable); | ||
} |