Skip to content

Commit

Permalink
fix: commentGroup 수정하는 로직 NativeQuery로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuny0310 committed Sep 23, 2023
1 parent 019e4bb commit 444584b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Comment, Long> {
@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<Comment> 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<Comment> 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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 444584b

Please sign in to comment.