Skip to content

Commit

Permalink
fix(Comment): 댓글 목록 조회에 삭제된 댓글이 포함되지 않는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee committed Jul 19, 2024
1 parent 21793cc commit b7b76f7
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PagedResponseDto<BoardCategoryResponseDto> retrieveBoardsByCategory(Board
MemberDetailedInfoDto currentMemberInfo = externalRetrieveMemberUseCase.getCurrentMemberDetailedInfo();
Page<Board> boards = retrieveBoardPort.findAllByCategory(category, pageable);
return new PagedResponseDto<>(boards.map(board -> {
long commentCount = externalRetrieveCommentUseCase.countCommentsByBoardId(board.getId());
long commentCount = externalRetrieveCommentUseCase.countByBoardId(board.getId());
return BoardCategoryResponseDto.toDto(board, currentMemberInfo, commentCount);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@RequestMapping("/api/v1/comments")
@RequiredArgsConstructor
@Tag(name = "Community - Comment", description = "커뮤니티 댓글")
public class CommentsRetrievalController {
public class CommentRetrievalController {

private final RetrieveCommentUseCase retrieveCommentUseCase;
private final PageableUtils pageableUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import page.clab.api.global.common.domain.BaseEntity;

import java.util.ArrayList;
Expand All @@ -33,7 +32,6 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Table(name = "comment", indexes = @Index(name = "comment_index", columnList = "boardId"))
@SQLDelete(sql = "UPDATE comment SET is_deleted = true WHERE id = ?")
@SQLRestriction("is_deleted = false")
public class CommentJpaEntity extends BaseEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,4 @@ public List<Comment> findByBoardId(Long boardId) {
.map(commentMapper::toDomain)
.toList();
}

@Override
public long countAllByBoardId(Long boardId) {
return commentRepository.countAllByBoardId(boardId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
@Repository
public interface CommentRepository extends JpaRepository<CommentJpaEntity, Long> {

@Query("SELECT c FROM CommentJpaEntity c WHERE c.boardId = ?1 AND c.parent.id IS NULL")
Page<CommentJpaEntity> findAllByBoardIdAndParentIsNull(Long boardId, Pageable pageable);

@Query("SELECT c FROM CommentJpaEntity c WHERE c.writerId = ?1 AND c.isDeleted = false")
Page<CommentJpaEntity> findAllByWriterId(String memberId, Pageable pageable);

@Query("SELECT COUNT(c) FROM CommentJpaEntity c WHERE c.boardId = ?1 AND c.isDeleted = false")
Long countByBoardId(Long boardId);

@Query(value = "SELECT c.* FROM comment c WHERE c.is_deleted = true AND c.board_id = ?", nativeQuery = true)
@Query("SELECT c FROM CommentJpaEntity c WHERE c.isDeleted = true AND c.boardId = ?1")
Page<CommentJpaEntity> findAllByIsDeletedTrueAndBoardId(Long boardId, Pageable pageable);

@Query("SELECT c FROM CommentJpaEntity c WHERE c.boardId = ?1 AND c.isDeleted = false")
List<CommentJpaEntity> findByBoardId(Long boardId);

long countAllByBoardId(Long boardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ public interface RetrieveCommentPort {
List<Comment> findByBoardId(Long boardId);

Long countByBoardId(Long boardId);

long countAllByBoardId(Long boardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ public interface ExternalRetrieveCommentUseCase {
Comment findByIdOrThrow(Long targetId);

Long countByBoardId(Long id);

long countCommentsByBoardId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ public Comment findByIdOrThrow(Long targetId) {
public Long countByBoardId(Long id) {
return retrieveCommentPort.countByBoardId(id);
}

@Transactional(readOnly = true)
@Override
public long countCommentsByBoardId(Long id) {
return retrieveCommentPort.countAllByBoardId(id);
}
}

0 comments on commit b7b76f7

Please sign in to comment.