Skip to content

Commit

Permalink
Merge pull request #94 from HyeJiJUN11/feature/92-comment
Browse files Browse the repository at this point in the history
feat: ๋Œ“๊ธ€ ๊ฐœ์ˆ˜ ๋ฐ˜ํ™˜ API ์ถ”๊ฐ€
  • Loading branch information
peeerr authored Nov 7, 2024
2 parents 43965da + 67139b5 commit b8cf90b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -60,4 +61,18 @@ public ResponseEntity<SuccessResponse<Void>> deleteComment(
return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

@Operation(summary = "๋Œ“๊ธ€ ๊ฐœ์ˆ˜", description = "ํŠน์ • ์ผ๊ธฐ์˜ ๋Œ“๊ธ€ ๊ฐœ์ˆ˜๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponse(responseCode = "200", description = "๋Œ“๊ธ€ ๊ฐœ์ˆ˜ ์กฐํšŒ ์„ฑ๊ณต")
@GetMapping("/{diaryId}/count")
public ResponseEntity<SuccessResponse<Void>> getCommentCount(
@Parameter(description = "์ธ์ฆ๋œ ์‚ฌ์šฉ์ž ์ •๋ณด", hidden = true)
@AuthenticationPrincipal MemberDetails memberDetails,
@Parameter(description = "๋Œ“๊ธ€ ๊ฐœ์ˆ˜๋ฅผ ์กฐํšŒํ•  ์ผ๊ธฐ ID", required = true)
@PathVariable Long diaryId) {
Long commentCount = commentService.getCommentCountByDiary(diaryId);

return ResponseEntity.ok()
.body(SuccessResponse.ok(commentCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
public class CommentResponse {
private Long id;
private Long memberId;
private CommentFriendResponse commentFriendResponse;
private String content;
private LocalDateTime createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface CommentRepository extends JpaRepository<Comment, Long> {
Page<Comment> findAllByDiaryId(Long diaryId, Pageable pageable);

Long countByDiaryId(Long diaryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ private CommentFriendResponse convertToCommentFriendResponseDTO(Member member) {
private CommentResponse convertToCommentResponseDTO(Comment comment) {
return CommentResponse.builder()
.id(comment.getId())
.memberId(comment.getMember().getId())
.commentFriendResponse(convertToCommentFriendResponseDTO(comment.getMember()))
.content(comment.getContent())
.createdAt(comment.getCreateAt())
.build();
}

public Long getCommentCountByDiary(Long diaryId) {
return commentRepository.countByDiaryId(diaryId);
}
}

0 comments on commit b8cf90b

Please sign in to comment.