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();;