diff --git a/src/main/java/univ/yesummit/domain/comment/api/CommentController.java b/src/main/java/univ/yesummit/domain/comment/api/CommentController.java index 70588de..84fcbb6 100644 --- a/src/main/java/univ/yesummit/domain/comment/api/CommentController.java +++ b/src/main/java/univ/yesummit/domain/comment/api/CommentController.java @@ -6,12 +6,14 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import univ.yesummit.domain.comment.api.dto.request.CommentSaveReqDto; import univ.yesummit.domain.comment.api.dto.request.CommentUpdateReqDto; import univ.yesummit.domain.comment.application.CommentService; +import univ.yesummit.global.resolver.LoginUser; +import univ.yesummit.global.resolver.User; @RestController @RequiredArgsConstructor @@ -23,11 +25,11 @@ public class CommentController { @Operation(summary = "댓글 등록", description = "댓글을 등록합니다.") @ApiResponse(responseCode = "200", description = "댓글 등록 성공") @ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))) - @PostMapping("/") - public ResponseEntity commentSave(@AuthenticationPrincipal String email, + @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity commentSave(@User LoginUser loginUser, @RequestBody CommentSaveReqDto commentSaveReqDto) { - commentService.commentSave(email, commentSaveReqDto); + commentService.commentSave(loginUser.getMemberId(), commentSaveReqDto); String responseMessage = String.format("%d 게시글에 댓글이 등록되었습니다.", commentSaveReqDto.boardId()); return ResponseEntity.status(HttpStatus.CREATED).body(responseMessage); @@ -36,12 +38,12 @@ public ResponseEntity commentSave(@AuthenticationPrincipal String email, @Operation(summary = "댓글 수정", description = "댓글을 수정합니다.") @ApiResponse(responseCode = "200", description = "댓글 수정 성공") @ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))) - @PutMapping("/{commentId}") - public ResponseEntity commentUpdate(@AuthenticationPrincipal String email, + @PutMapping(value = "/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity commentUpdate(@User LoginUser loginUser, @PathVariable("commentId") Long commentId, @RequestBody CommentUpdateReqDto commentUpdateReqDto) { - commentService.commentUpdate(email, commentId, commentUpdateReqDto); + commentService.commentUpdate(loginUser.getMemberId(), commentId, commentUpdateReqDto); String responseMessage = String.format("%d 게시글의 댓글이 수정돠었습니다.", commentId); return ResponseEntity.status(HttpStatus.OK).body(responseMessage); @@ -50,10 +52,10 @@ public ResponseEntity commentUpdate(@AuthenticationPrincipal String emai @Operation(summary = "댓글 삭제", description = "댓글을 삭제합니다.") @ApiResponse(responseCode = "200", description = "댓글 삭제 성공") @ApiResponse(responseCode = "401", description = "인증 실패", content = @Content(schema = @Schema(example = "INVALID_HEADER or INVALID_TOKEN"))) - @DeleteMapping("/{commentId}") - public ResponseEntity commentDelete(@AuthenticationPrincipal String email, + @DeleteMapping(value = "/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity commentDelete(@User LoginUser loginUser, @PathVariable("commentId") Long commentId) { - commentService.commentDelete(email, commentId); + commentService.commentDelete(loginUser.getMemberId(), commentId); String responseMessage = String.format("%d 게시글의 댓글이 삭제되었습니다.", commentId); return ResponseEntity.status(HttpStatus.OK).body(responseMessage); diff --git a/src/main/java/univ/yesummit/domain/comment/application/CommentService.java b/src/main/java/univ/yesummit/domain/comment/application/CommentService.java index d9d53f8..42bfac1 100644 --- a/src/main/java/univ/yesummit/domain/comment/application/CommentService.java +++ b/src/main/java/univ/yesummit/domain/comment/application/CommentService.java @@ -24,8 +24,8 @@ public class CommentService { // 댓글 저장 @Transactional - public void commentSave(String email, CommentSaveReqDto commentSaveReqDto) { - Member member = memberRepository.findByEmail(email) + public void commentSave(Long id, CommentSaveReqDto commentSaveReqDto) { + Member member = memberRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다.")); Board board = boardRepository.findById(commentSaveReqDto.boardId()) @@ -36,8 +36,8 @@ public void commentSave(String email, CommentSaveReqDto commentSaveReqDto) { // 댓글 수정 @Transactional - public CommentInfoResDto commentUpdate(String email, Long commentId, CommentUpdateReqDto commentUpdateReqDto){ - Member member = memberRepository.findByEmail(email) + public CommentInfoResDto commentUpdate(Long id, Long commentId, CommentUpdateReqDto commentUpdateReqDto){ + Member member = memberRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다.")); Comment comment = commentRepository.findById(commentId) @@ -52,8 +52,8 @@ public CommentInfoResDto commentUpdate(String email, Long commentId, CommentUpda // 댓글 삭제 @Transactional - public void commentDelete(String email, Long commentId) { - Member member = memberRepository.findByEmail(email) + public void commentDelete(Long id, Long commentId) { + Member member = memberRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("회원이 존재하지 않습니다.")); Comment comment = commentRepository.findById(commentId)