Skip to content

Commit

Permalink
Refactor: api uri 수정 및 순환 참조 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
resource777 committed Nov 3, 2023
1 parent d007b61 commit 6d8b4d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class BoardController {
private final MemberService memberService;
@Operation(description = "특정 캐릭터 게시판 게시글 작성")
@PostMapping("/boards/{characterId}")
public ResponseEntity<Board> addBoard(@PathVariable Long characterId,
public ResponseEntity<BoardResponse> 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 = "특정 캐릭터 게시판 모든 게시글 조회")
Expand Down Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<Void> deleteBoard(@PathVariable long postId, @Login Claims

@Operation(description = "특정 캐릭터 게시판 특정 게시글 수정")
@PutMapping("/boards/{characterId}/{postId}")
public ResponseEntity<Board> updateBoard(
public ResponseEntity<BoardResponse> updateBoard(
@PathVariable long postId,
@RequestBody UpdateBoardRequest request,
@Login Claims claims
Expand All @@ -96,6 +96,6 @@ public ResponseEntity<Board> updateBoard(
Board updateArticle = boardService.update(postId, request);

return ResponseEntity.ok()
.body(updateArticle);
.body(new BoardResponse(updateArticle));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Comment> commentList = article.getComments();
if (commentList != null) {
this.comments = commentList.stream().map(CommentResponseDto::new).collect(Collectors.toList());
}
this.likeCount = article.getLikeCount();
this.commentCount = article.getCommentCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public ResponseEntity commentSave(
}

@GetMapping("/{postId}")
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable Long articleId) {
List<CommentResponseDto> comments = commentService.getCommentsByArticleId(articleId)
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable Long postId) {
List<CommentResponseDto> comments = commentService.getCommentsByArticleId(postId)
.stream()
.map(CommentResponseDto::new)
.toList();;
Expand Down

0 comments on commit 6d8b4d7

Please sign in to comment.