Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

커뮤니티 게시글 조회 API 개선 완료 #357

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public PagedResponseDto<BoardMyResponseDto> getMyBoards(Pageable pageable) {
@Transactional(readOnly = true)
public PagedResponseDto<BoardCategoryResponseDto> getBoardsByCategory(BoardCategory category, Pageable pageable) {
Page<Board> boards = getBoardByCategory(category, pageable);
return new PagedResponseDto<>(boards.map(BoardCategoryResponseDto::toDto));
return new PagedResponseDto<>(boards.map(this::mapToBoardCategoryResponseDto));
}

@Transactional
Expand Down Expand Up @@ -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("해당 게시글이 존재하지 않습니다."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ 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())
.category(board.getCategory().getKey())
.writerId(writerInfo.getId())
.writerName(writerInfo.getName())
.title(board.getTitle())
.commentCount(commentCount)
.imageUrl(board.getImageUrl())
.createdAt(board.getCreatedAt())
.build();
Expand Down
Loading