Skip to content

Commit

Permalink
내 댓글 조회시 발생하는 오류 수정 완료 (#333)
Browse files Browse the repository at this point in the history
* fix(Comment): 나의 댓글 조회시 삭제된 게시글이 포함되어 NullPointerException이 발생하는 문제 수정

* fix(Comment): 내 댓글 조회시 삭제된 댓글이 포함되는 문제 수정
  • Loading branch information
limehee authored May 5, 2024
1 parent 17f0cc1 commit a47374c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import page.clab.api.global.exception.PermissionDeniedException;
import page.clab.api.global.validation.ValidationService;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -65,8 +67,12 @@ public PagedResponseDto<CommentResponseDto> getAllComments(Long boardId, Pageabl
public PagedResponseDto<CommentMyResponseDto> getMyComments(Pageable pageable) {
Member currentMember = memberService.getCurrentMember();
Page<Comment> comments = getCommentByWriter(currentMember, pageable);
Page<CommentMyResponseDto> commentDtos = comments.map(comment -> toCommentMyResponseDto(comment, currentMember));
return new PagedResponseDto<>(commentDtos);
List<CommentMyResponseDto> dtos = comments
.map(comment -> toCommentMyResponseDto(comment, currentMember))
.stream()
.filter(Objects::nonNull)
.toList();
return new PagedResponseDto<>(dtos, pageable, dtos.size());
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -167,7 +173,7 @@ private void setLikeStatusForChildren(CommentResponseDto responseDto, Member mem
}

private CommentMyResponseDto toCommentMyResponseDto(Comment comment, Member currentMember) {
Boolean hasLikeByMe = checkLikeStatus(comment.getId(), currentMember.getId());
boolean hasLikeByMe = checkLikeStatus(comment.getId(), currentMember.getId());
return CommentMyResponseDto.toDto(comment, hasLikeByMe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class CommentMyResponseDto {
private LocalDateTime createdAt;

public static CommentMyResponseDto toDto(Comment comment, boolean hasLikeByMe) {
if (comment.getBoard() == null || comment.getIsDeleted()) {
return null;
}
return CommentMyResponseDto.builder()
.id(comment.getId())
.boardId(comment.getBoard().getId())
Expand Down

0 comments on commit a47374c

Please sign in to comment.