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 @@ -3,6 +3,7 @@
import com.back.domain.post.comment.dto.request.CommentCreateRequestDto;
import com.back.domain.post.comment.dto.response.CommentResponseDto;
import com.back.domain.post.comment.service.CommentService;
import com.back.domain.post.post.dto.response.PostResponseDto;
import com.back.global.rsData.RsData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -48,4 +49,13 @@ public RsData<List<CommentResponseDto>> getComments(
) {
return RsData.successOf(commentService.getComments(postId, lastId)); // code=200, message="success"
}

@GetMapping("/{commentId}")
@Operation(summary = "댓글 단건 조회")
public RsData<CommentResponseDto> getComment(
@PathVariable Long postId,
@PathVariable Long commentId
) {
return RsData.successOf(commentService.getComment(postId, commentId)); // code=200, message="success"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ public List<CommentResponseDto> getComments(Long postId, Long lastId) {
.toList();
}
}

// 댓글 단건 조회 로직
@Transactional(readOnly = true)
public CommentResponseDto getComment(Long postId, Long commentId) {
Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new IllegalArgumentException("댓글이 존재하지 않습니다. id=" + commentId));

if (!comment.getPost().getId().equals(postId)) {
throw new IllegalStateException("댓글이 해당 게시글에 속하지 않습니다.");
}

return new CommentResponseDto(comment);
}
}