Skip to content

Commit 69b848b

Browse files
authored
채택된 댓글 조회 (#137)
1 parent 01e78e1 commit 69b848b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

back/src/main/java/com/back/domain/post/comment/controller/PostCommentController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.back.domain.post.comment.dto.CommentCreateRequest;
66
import com.back.domain.post.comment.dto.CommentDeleteRequest;
77
import com.back.domain.post.comment.dto.CommentModifyRequest;
8+
import com.back.domain.post.comment.entity.PostComment;
89
import com.back.domain.post.comment.service.PostCommentService;
910
import com.back.global.rq.Rq;
1011
import com.back.global.rsData.RsData;
@@ -75,4 +76,12 @@ public RsData<Void> adoptComment(@PathVariable Long commentId) {
7576
return new RsData<>("200", "댓글 채택 성공", null);
7677
}
7778

79+
@Operation(summary = "채택된 댓글 가져오기 ")
80+
@GetMapping("isAdopted/{post_id}")
81+
public RsData<CommentAllResponse> getAdoptComment(@PathVariable Long post_id) {
82+
CommentAllResponse commentAllResponse = postCommentService.getAdoptedComment(post_id);
83+
84+
return new RsData<>("200", "채택된 댓글 조회 성공", commentAllResponse);
85+
}
86+
7887
}

back/src/main/java/com/back/domain/post/comment/repository/PostCommentRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.stereotype.Repository;
99

1010
import java.util.List;
11+
import java.util.Optional;
1112

1213
@Repository
1314
public interface PostCommentRepository extends JpaRepository<PostComment, Long> {
@@ -17,4 +18,6 @@ public interface PostCommentRepository extends JpaRepository<PostComment, Long>
1718

1819

1920
boolean existsByPostAndIsAdoptedTrue(Post post);
21+
22+
Optional<PostComment> findByPostAndIsAdoptedTrue(Post post);
2023
}

back/src/main/java/com/back/domain/post/comment/service/PostCommentService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,19 @@ public void adoptComment(Long commentId, Member member) {
137137

138138
post.updateResolveStatus(true);
139139
}
140+
141+
@Transactional
142+
public CommentAllResponse getAdoptedComment(Long postId) {
143+
Post post = postRepository.findById(postId)
144+
.orElseThrow(() -> new ServiceException("400", "해당 Id의 게시글이 없습니다."));
145+
146+
if (post.getPostType() != Post.PostType.QUESTIONPOST) {
147+
throw new ServiceException("400", "질문 게시글만 채택된 댓글을 가질 수 있습니다.");
148+
}
149+
150+
PostComment postComment = postCommentRepository.findByPostAndIsAdoptedTrue(post)
151+
.orElseThrow(() -> new ServiceException("400", "채택된 댓글이 없습니다."));
152+
153+
return CommentAllResponse.from(postComment);
154+
}
140155
}

0 commit comments

Comments
 (0)