From 444584b2200b510539fe9266ffa5ba0cba99bb23 Mon Sep 17 00:00:00 2001 From: jjuny7712 Date: Sat, 23 Sep 2023 18:28:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20commentGroup=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20NativeQuery=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/domain/Comment.java | 1 + .../comment/repository/CommentRepository.java | 28 ++++++++++++------- .../comment/service/CommentService.java | 3 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/ssafy/ssafsound/domain/comment/domain/Comment.java b/src/main/java/com/ssafy/ssafsound/domain/comment/domain/Comment.java index 9ce1c141f..694e4a90e 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/comment/domain/Comment.java +++ b/src/main/java/com/ssafy/ssafsound/domain/comment/domain/Comment.java @@ -1,6 +1,7 @@ package com.ssafy.ssafsound.domain.comment.domain; import com.ssafy.ssafsound.domain.BaseTimeEntity; +import com.ssafy.ssafsound.domain.comment.dto.PostCommentWriteReqDto; import com.ssafy.ssafsound.domain.member.domain.Member; import com.ssafy.ssafsound.domain.post.domain.Post; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/ssafy/ssafsound/domain/comment/repository/CommentRepository.java b/src/main/java/com/ssafy/ssafsound/domain/comment/repository/CommentRepository.java index 6d1074955..6adee2a36 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/comment/repository/CommentRepository.java +++ b/src/main/java/com/ssafy/ssafsound/domain/comment/repository/CommentRepository.java @@ -1,21 +1,29 @@ package com.ssafy.ssafsound.domain.comment.repository; -import com.ssafy.ssafsound.domain.comment.domain.Comment; -import org.springframework.data.domain.Pageable; +import java.util.List; + 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 java.util.List; +import com.ssafy.ssafsound.domain.comment.domain.Comment; @Repository public interface CommentRepository extends JpaRepository { - @Query("SELECT c FROM comment c " + - "JOIN FETCH c.commentNumber " + - "JOIN FETCH c.member " + - "JOIN FETCH c.commentGroup g " + - "WHERE c.post.id = :postId " + - "ORDER BY g.id ") - List findAllPostIdWithDetailsFetchOrderByCommentGroupId(@Param("postId") Long postId); + @Query("SELECT c FROM comment c " + + "JOIN FETCH c.commentNumber " + + "JOIN FETCH c.member " + + "JOIN FETCH c.commentGroup g " + + "WHERE c.post.id = :postId " + + "ORDER BY g.id ") + List findAllPostIdWithDetailsFetchOrderByCommentGroupId(@Param("postId") Long postId); + + @Modifying + @Query(value = "update comment " + + "set comment_group = :id " + + "where comment_id = :id", nativeQuery = true) + void updateByCommentGroup(@Param("id") Long id); + } diff --git a/src/main/java/com/ssafy/ssafsound/domain/comment/service/CommentService.java b/src/main/java/com/ssafy/ssafsound/domain/comment/service/CommentService.java index 3d83b35d2..8ac19cfe4 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/comment/service/CommentService.java +++ b/src/main/java/com/ssafy/ssafsound/domain/comment/service/CommentService.java @@ -14,6 +14,7 @@ import com.ssafy.ssafsound.domain.member.exception.MemberErrorInfo; import com.ssafy.ssafsound.domain.member.exception.MemberException; import com.ssafy.ssafsound.domain.member.repository.MemberRepository; +import com.ssafy.ssafsound.domain.post.domain.Post; import com.ssafy.ssafsound.domain.post.dto.PostCommonLikeResDto; import com.ssafy.ssafsound.domain.post.exception.PostErrorInfo; import com.ssafy.ssafsound.domain.post.exception.PostException; @@ -69,7 +70,7 @@ public CommentIdElement writeComment(Long postId, Long loginMemberId, PostCommen .build(); comment = commentRepository.save(comment); - comment.setCommentGroup(comment); + commentRepository.updateByCommentGroup(comment.getId()); return new CommentIdElement(comment.getId()); }