diff --git a/src/main/java/page/clab/api/domain/board/application/BoardService.java b/src/main/java/page/clab/api/domain/board/application/BoardService.java index 32723d5b2..edf6a713b 100644 --- a/src/main/java/page/clab/api/domain/board/application/BoardService.java +++ b/src/main/java/page/clab/api/domain/board/application/BoardService.java @@ -87,7 +87,7 @@ public PagedResponseDto getMyBoards(Pageable pageable) { @Transactional(readOnly = true) public PagedResponseDto getBoardsByCategory(BoardCategory category, Pageable pageable) { Page boards = getBoardByCategory(category, pageable); - return new PagedResponseDto<>(boards.map(BoardCategoryResponseDto::toDto)); + return new PagedResponseDto<>(boards.map(this::mapToBoardCategoryResponseDto)); } @Transactional @@ -137,6 +137,12 @@ private BoardListResponseDto mapToBoardListResponseDto(Board board) { return BoardListResponseDto.toDto(board, commentCount); } + @NotNull + private BoardCategoryResponseDto mapToBoardCategoryResponseDto(Board board) { + Long commentCount = commentRepository.countByBoard(board); + return BoardCategoryResponseDto.toDto(board, commentCount); + } + public Board getBoardByIdOrThrow(Long boardId) { return boardRepository.findById(boardId) .orElseThrow(() -> new NotFoundException("해당 게시글이 존재하지 않습니다.")); diff --git a/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java b/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java index 20290fe66..aaa19f054 100644 --- a/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java +++ b/src/main/java/page/clab/api/domain/board/dto/response/BoardCategoryResponseDto.java @@ -21,11 +21,13 @@ public class BoardCategoryResponseDto { private String title; + private Long commentCount; + private String imageUrl; private LocalDateTime createdAt; - public static BoardCategoryResponseDto toDto(Board board) { + public static BoardCategoryResponseDto toDto(Board board, Long commentCount) { WriterInfo writerInfo = WriterInfo.fromBoard(board); return BoardCategoryResponseDto.builder() .id(board.getId()) @@ -33,6 +35,7 @@ public static BoardCategoryResponseDto toDto(Board board) { .writerId(writerInfo.getId()) .writerName(writerInfo.getName()) .title(board.getTitle()) + .commentCount(commentCount) .imageUrl(board.getImageUrl()) .createdAt(board.getCreatedAt()) .build();