Skip to content

Commit

Permalink
feat: 한줄평 관련 JPA 인터페이스 추가
Browse files Browse the repository at this point in the history
Related to: #139
Ref: #136
  • Loading branch information
hgh1472 committed Oct 20, 2024
1 parent af49590 commit 5863a9e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
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);
}
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);
}
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);
}

0 comments on commit 5863a9e

Please sign in to comment.