diff --git a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java index eea2686..c72de62 100644 --- a/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/ClipBoardController.java @@ -70,7 +70,7 @@ public ApplicationResponse findClipBoard(@RequestBody @Validate @ApiResponse(code = 4000 , message = "서버 오류입니다.") }) @PostMapping("/get/all") - public ApplicationResponse> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ + public ApplicationResponse> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){ return clipBoardService.findAllClipBoards(getAllClipBoardsReq); } } diff --git a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java index 559ad05..4385ec3 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/clipboard/GetClipBoardRes.java @@ -40,6 +40,10 @@ public class GetClipBoardRes { @ApiParam(value = "코멘트들") private List commentResList; + @ApiModelProperty(example = "2") + @ApiParam(value = "클립보드에 달린 코멘트 갯수") + private Integer commentCnt; + @ApiModelProperty(example = "ACTIVE") @ApiParam(value = "객체 상태") private BaseStatus status; @@ -60,6 +64,7 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List commen .title(clipBoard.getTitle()) .content(clipBoard.getContent()) .commentResList(commentResList) + .commentCnt(commentResList.size()) .status(clipBoard.getStatus()) .createdAt(clipBoard.getCreatedAt()) .updatedAt(clipBoard.getUpdatedAt()) @@ -67,14 +72,14 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List commen } @Builder - - public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List commentResList, BaseStatus status, String createdAt, String updatedAt) { + public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List commentResList, Integer commentCnt, BaseStatus status, String createdAt, String updatedAt) { this.clipBoardId = clipBoardId; this.userId = userId; this.boardId = boardId; this.title = title; this.content = content; this.commentResList = commentResList; + this.commentCnt = commentCnt; this.status = status; this.createdAt = createdAt; this.updatedAt = updatedAt; diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java index 9bce9de..f62d26c 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardService.java @@ -15,5 +15,5 @@ public interface ClipBoardService { ApplicationResponse findClipBoard(GetClipBoardReq getClipBoardReq); - ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); + ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq); } diff --git a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java index 37aa717..a9af588 100644 --- a/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/clipboard/ClipBoardServiceImpl.java @@ -79,7 +79,7 @@ public ApplicationResponse findClipBoard(GetClipBoardReq dto){ @Transactional(readOnly = true) @Override - public ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq dto){ + public ApplicationResponse> findAllClipBoards(GetAllClipBoardsReq dto){ User user = userRepository.findById(dto.getUserId()) .orElseThrow(() -> new NotFoundUserException()); @@ -87,10 +87,13 @@ public ApplicationResponse> findAllClipBoards(GetAllClipBoard Board board = boardRepository.findBoardById(dto.getBoardId()) .orElseThrow(() -> new NotFoundBoardException()); - List clipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream() - .map(clipBoard -> ClipBoardRes.toDto(clipBoard)) + // 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함 + List getClipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream() + .map(clipBoard -> GetClipBoardRes.toDto(clipBoard, commentRepository.findAllCommentsByClipBoardId(clipBoard.getId()).stream() + .map(comment -> CommentRes.toDto(comment)) + .collect(Collectors.toList()))) .collect(Collectors.toList()); - return ApplicationResponse.ok(clipBoardResList); + return ApplicationResponse.ok(getClipBoardResList); } }