Skip to content

Commit

Permalink
[Fix] 비회원도 댓글 조회 가능하게 토큰 인증 수정 #206 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
yr0202 authored Feb 4, 2025
2 parents 43ec5bd + 61636b9 commit c74316e
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ public ResponseEntity<LongCursorResponse<CommentReadResponse>> getAllCommentsByP
@RequestParam(required = false) Long cursorKey,
@RequestParam(defaultValue = "10") Integer size) {

if (auth == null || auth.getId() == null) {
throw new GeneralException(ResponseCode.EMPTY_TOKEN);
String memberId = null; // 비회원일 경우 null

// 로그인한 사용자일 경우
if (auth != null && auth.getId() != null) {
memberId = auth.getId();
}

// cursorRequest 객체 생성
CursorRequest<Long> cursorRequest = new CursorRequest<>(cursorKey, size);

LongCursorResponse<CommentReadResponse> response = commentService.getAllCommentsByPostId(postId, cursorRequest,
auth.getId());
memberId);

return ResponseEntity.ok(response);
}
Expand All @@ -66,8 +70,8 @@ public ResponseEntity<LongCursorResponse<CommentReadResponse>> getAllCommentsByP
public ResponseEntity<Void> registerCommentByPostId(
@AuthenticationPrincipal CustomOAuth2User auth,
@RequestParam Long postId,
@RequestBody @Valid CommentRegisterRequest request
) {
@RequestBody @Valid CommentRegisterRequest request) {

if (auth == null || auth.getId() == null) {
throw new GeneralException(ResponseCode.EMPTY_TOKEN);
}
Expand All @@ -85,8 +89,8 @@ public ResponseEntity<Void> registerCommentByPostId(
public ResponseEntity<Void> updateCommentByPostId(
@AuthenticationPrincipal CustomOAuth2User auth,
@PathVariable Long commentId,
@RequestBody @Valid CommentUpdateRequest request
) {
@RequestBody @Valid CommentUpdateRequest request) {

if (auth == null || auth.getId() == null) {
throw new GeneralException(ResponseCode.EMPTY_TOKEN);
}
Expand Down

0 comments on commit c74316e

Please sign in to comment.