diff --git a/src/main/java/com/kusitms/samsion/domain/album/infrastructure/AlbumRepositoryImpl.java b/src/main/java/com/kusitms/samsion/domain/album/infrastructure/AlbumRepositoryImpl.java index 38be7ba..8825cac 100644 --- a/src/main/java/com/kusitms/samsion/domain/album/infrastructure/AlbumRepositoryImpl.java +++ b/src/main/java/com/kusitms/samsion/domain/album/infrastructure/AlbumRepositoryImpl.java @@ -3,9 +3,6 @@ import com.kusitms.samsion.common.querydsl.OrderByNull; import com.kusitms.samsion.domain.album.domain.entity.*; import com.kusitms.samsion.domain.album.domain.repository.AlbumRepositoryCustom; -import com.kusitms.samsion.domain.comment.domain.entity.QComment; -import com.querydsl.core.types.Expression; -import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPAExpressions; @@ -85,17 +82,10 @@ private OrderSpecifier getSortedColumn(SortType sortType) { case EMPATHY: return QAlbum.album.empathies.size().desc(); case COMMENT: - return new OrderSpecifier<>(Order.DESC, getCommentSubQuery()); + return QAlbum.album.comments.size().desc(); } return OrderByNull.getDefault(); } - private Expression getCommentSubQuery() { - return JPAExpressions.select(QComment.comment.id.count()) - .from(QComment.comment) - .where(QComment.comment.deleted.isFalse(), - QComment.comment.album.id.eq(QAlbum.album.id)); - } - } diff --git a/src/main/java/com/kusitms/samsion/domain/comment/domain/entity/Comment.java b/src/main/java/com/kusitms/samsion/domain/comment/domain/entity/Comment.java index 6e79c7b..3b324b2 100644 --- a/src/main/java/com/kusitms/samsion/domain/comment/domain/entity/Comment.java +++ b/src/main/java/com/kusitms/samsion/domain/comment/domain/entity/Comment.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.util.ArrayList; @@ -15,7 +16,8 @@ @Getter @Entity @NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) -@SQLDelete(sql = "UPDATE comment SET deleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE comment SET deleted = true WHERE comment_id = ?") +@Where(clause = "deleted = false") public class Comment extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -40,7 +42,7 @@ public class Comment extends BaseEntity { private Comment parent; //자식 정의 (대댓글) - @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) private List childList = new ArrayList<>(); public void addChild(Comment child){ diff --git a/src/main/java/com/kusitms/samsion/domain/comment/presentation/CommentController.java b/src/main/java/com/kusitms/samsion/domain/comment/presentation/CommentController.java index 72ac0b9..8abbfb4 100644 --- a/src/main/java/com/kusitms/samsion/domain/comment/presentation/CommentController.java +++ b/src/main/java/com/kusitms/samsion/domain/comment/presentation/CommentController.java @@ -43,7 +43,7 @@ public CommentInfoResponse update(@PathVariable Long commentId, @RequestBody Com return commentUpdateUseCase.updateComment(commentId, commentUpdateRequest); } - @CacheEvict(value = CachingStoreConst.COMMENT_COUNT_CACHE_NAME, key = "#albumId") + @CacheEvict(value = CachingStoreConst.COMMENT_COUNT_CACHE_NAME, key = "#albumId",condition="#albumId!=null") @DeleteMapping("/{albumId}/comment/{commentId}") public void delete(@PathVariable Long commentId){ commentDeleteUseCase.deleteComment(commentId);