Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.back.domain.post.comment.dto.CommentCreateRequest;
import com.back.domain.post.comment.dto.CommentDeleteRequest;
import com.back.domain.post.comment.dto.CommentModifyRequest;
import com.back.domain.post.comment.entity.PostComment;
import com.back.domain.post.comment.service.PostCommentService;
import com.back.global.rq.Rq;
import com.back.global.rsData.RsData;
Expand Down Expand Up @@ -75,4 +76,12 @@ public RsData<Void> adoptComment(@PathVariable Long commentId) {
return new RsData<>("200", "댓글 채택 성공", null);
}

@Operation(summary = "채택된 댓글 가져오기 ")
@GetMapping("isAdopted/{post_id}")
public RsData<CommentAllResponse> getAdoptComment(@PathVariable Long post_id) {
CommentAllResponse commentAllResponse = postCommentService.getAdoptedComment(post_id);

return new RsData<>("200", "채택된 댓글 조회 성공", commentAllResponse);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PostCommentRepository extends JpaRepository<PostComment, Long> {
Expand All @@ -17,4 +18,6 @@ public interface PostCommentRepository extends JpaRepository<PostComment, Long>


boolean existsByPostAndIsAdoptedTrue(Post post);

Optional<PostComment> findByPostAndIsAdoptedTrue(Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,19 @@ public void adoptComment(Long commentId, Member member) {

post.updateResolveStatus(true);
}

@Transactional
public CommentAllResponse getAdoptedComment(Long postId) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new ServiceException("400", "해당 Id의 게시글이 없습니다."));

if (post.getPostType() != Post.PostType.QUESTIONPOST) {
throw new ServiceException("400", "질문 게시글만 채택된 댓글을 가질 수 있습니다.");
}

PostComment postComment = postCommentRepository.findByPostAndIsAdoptedTrue(post)
.orElseThrow(() -> new ServiceException("400", "채택된 댓글이 없습니다."));

return CommentAllResponse.from(postComment);
}
}