Skip to content

Commit

Permalink
#23 feat: GetAllClipBoard 클립보드 전체조회 시 코멘트 갯수 계산 API구현, fix:GetClipBoa…
Browse files Browse the repository at this point in the history
…rdRes commentCnt필드값 추가
  • Loading branch information
xhaktmchl committed Nov 8, 2022
1 parent ab3b88a commit e504ea6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ApplicationResponse<GetClipBoardRes> findClipBoard(@RequestBody @Validate
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("/get/all")
public ApplicationResponse<List<ClipBoardRes>> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){
public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(@RequestBody @Validated GetAllClipBoardsReq getAllClipBoardsReq){
return clipBoardService.findAllClipBoards(getAllClipBoardsReq);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class GetClipBoardRes {
@ApiParam(value = "코멘트들")
private List<CommentRes> commentResList;

@ApiModelProperty(example = "2")
@ApiParam(value = "클립보드에 달린 코멘트 갯수")
private Integer commentCnt;

@ApiModelProperty(example = "ACTIVE")
@ApiParam(value = "객체 상태")
private BaseStatus status;
Expand All @@ -60,21 +64,22 @@ public static GetClipBoardRes toDto(ClipBoard clipBoard, List<CommentRes> commen
.title(clipBoard.getTitle())
.content(clipBoard.getContent())
.commentResList(commentResList)
.commentCnt(commentResList.size())
.status(clipBoard.getStatus())
.createdAt(clipBoard.getCreatedAt())
.updatedAt(clipBoard.getUpdatedAt())
.build();
}

@Builder

public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List<CommentRes> commentResList, BaseStatus status, String createdAt, String updatedAt) {
public GetClipBoardRes(Long clipBoardId, Long userId, Long boardId, String title, String content, List<CommentRes> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface ClipBoardService {

ApplicationResponse<GetClipBoardRes> findClipBoard(GetClipBoardReq getClipBoardReq);

ApplicationResponse<List<ClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq);
ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq getAllClipBoardsReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ public ApplicationResponse<GetClipBoardRes> findClipBoard(GetClipBoardReq dto){

@Transactional(readOnly = true)
@Override
public ApplicationResponse<List<ClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq dto){
public ApplicationResponse<List<GetClipBoardRes>> findAllClipBoards(GetAllClipBoardsReq dto){

User user = userRepository.findById(dto.getUserId())
.orElseThrow(() -> new NotFoundUserException());

Board board = boardRepository.findBoardById(dto.getBoardId())
.orElseThrow(() -> new NotFoundBoardException());

List<ClipBoardRes> clipBoardResList = clipBoardRepository.findAllByBoardId(dto.getBoardId()).stream()
.map(clipBoard -> ClipBoardRes.toDto(clipBoard))
// 클립보드 res안에 해당하는 코멘트 리스트까지 조회 및 포함
List<GetClipBoardRes> 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);
}
}

0 comments on commit e504ea6

Please sign in to comment.