From 6d8b4d7b956fbad02c2c980243b6ae329b73f0b1 Mon Sep 17 00:00:00 2001 From: resource777 <79133019+resource777@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:44:22 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20api=20uri=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=88=9C=ED=99=98=20=EC=B0=B8=EC=A1=B0=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../toonchat/domain/board/controller/BoardController.java | 8 ++++---- .../toonchat/domain/board/dto/BoardResponse.java | 6 +++++- .../domain/comment/controller/CommentController.java | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/webtoonchat/toonchat/domain/board/controller/BoardController.java b/src/main/java/com/webtoonchat/toonchat/domain/board/controller/BoardController.java index e372f63..92e4c1a 100644 --- a/src/main/java/com/webtoonchat/toonchat/domain/board/controller/BoardController.java +++ b/src/main/java/com/webtoonchat/toonchat/domain/board/controller/BoardController.java @@ -35,14 +35,14 @@ public class BoardController { private final MemberService memberService; @Operation(description = "특정 캐릭터 게시판 게시글 작성") @PostMapping("/boards/{characterId}") - public ResponseEntity addBoard(@PathVariable Long characterId, + public ResponseEntity addBoard(@PathVariable Long characterId, @RequestBody AddBoardRequest request, @Login Claims claims) { Long userId = claims.get("userId", Long.class); Member member = memberService.findByMemberId(userId); Board savedArticle = boardService.save(request, characterId, member.getName(), userId); return ResponseEntity.status(HttpStatus.CREATED) - .body(savedArticle); + .body(new BoardResponse(savedArticle)); } @Operation(description = "특정 캐릭터 게시판 모든 게시글 조회") @@ -82,7 +82,7 @@ public ResponseEntity deleteBoard(@PathVariable long postId, @Login Claims @Operation(description = "특정 캐릭터 게시판 특정 게시글 수정") @PutMapping("/boards/{characterId}/{postId}") - public ResponseEntity updateBoard( + public ResponseEntity updateBoard( @PathVariable long postId, @RequestBody UpdateBoardRequest request, @Login Claims claims @@ -96,6 +96,6 @@ public ResponseEntity updateBoard( Board updateArticle = boardService.update(postId, request); return ResponseEntity.ok() - .body(updateArticle); + .body(new BoardResponse(updateArticle)); } } diff --git a/src/main/java/com/webtoonchat/toonchat/domain/board/dto/BoardResponse.java b/src/main/java/com/webtoonchat/toonchat/domain/board/dto/BoardResponse.java index e83d515..a08ec18 100644 --- a/src/main/java/com/webtoonchat/toonchat/domain/board/dto/BoardResponse.java +++ b/src/main/java/com/webtoonchat/toonchat/domain/board/dto/BoardResponse.java @@ -6,6 +6,7 @@ import com.webtoonchat.toonchat.domain.board.entity.Board; import com.webtoonchat.toonchat.domain.comment.dto.CommentResponseDto; +import com.webtoonchat.toonchat.domain.comment.entity.Comment; import lombok.Getter; @@ -33,7 +34,10 @@ public BoardResponse(Board article) { this.createdAt = article.getCreatedAt(); this.characterId = article.getCharacterId(); this.updatedAt = article.getUpdatedAt(); - this.comments = article.getComments().stream().map(CommentResponseDto::new).collect(Collectors.toList()); + List commentList = article.getComments(); + if (commentList != null) { + this.comments = commentList.stream().map(CommentResponseDto::new).collect(Collectors.toList()); + } this.likeCount = article.getLikeCount(); this.commentCount = article.getCommentCount(); } diff --git a/src/main/java/com/webtoonchat/toonchat/domain/comment/controller/CommentController.java b/src/main/java/com/webtoonchat/toonchat/domain/comment/controller/CommentController.java index 55b0387..f15e93f 100644 --- a/src/main/java/com/webtoonchat/toonchat/domain/comment/controller/CommentController.java +++ b/src/main/java/com/webtoonchat/toonchat/domain/comment/controller/CommentController.java @@ -41,8 +41,8 @@ public ResponseEntity commentSave( } @GetMapping("/{postId}") - public ResponseEntity> getComments(@PathVariable Long articleId) { - List comments = commentService.getCommentsByArticleId(articleId) + public ResponseEntity> getComments(@PathVariable Long postId) { + List comments = commentService.getCommentsByArticleId(postId) .stream() .map(CommentResponseDto::new) .toList();;