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()); }