diff --git a/src/main/java/run/halo/app/repository/JournalCommentRepository.java b/src/main/java/run/halo/app/repository/JournalCommentRepository.java index 5da988bf0..279846e01 100644 --- a/src/main/java/run/halo/app/repository/JournalCommentRepository.java +++ b/src/main/java/run/halo/app/repository/JournalCommentRepository.java @@ -5,6 +5,7 @@ import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.lang.NonNull; import run.halo.app.model.entity.JournalComment; +import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.projection.CommentChildrenCountProjection; import run.halo.app.model.projection.CommentCountProjection; import run.halo.app.repository.base.BaseCommentRepository; @@ -33,6 +34,25 @@ public interface JournalCommentRepository extends BaseCommentRepository countByPostIds(@NonNull Collection postIds); + /** + * Counts comment count by comment status and journal id collection. + * + * @param status status must not be null + * @param journalsId journal id collection must not be null + * @return a list of comment count + */ + @Query( + "select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), " + + "comment.postId) " + + "from JournalComment comment " + + "where comment.status = ?1 " + + "and comment.postId in ?2 " + + "group by comment.postId") + @NonNull + @Override + List countByStatusAndPostIds(@NonNull CommentStatus status, + @NonNull Collection journalsId); + /** * Finds direct children count by comment ids. * diff --git a/src/main/java/run/halo/app/repository/PostCommentRepository.java b/src/main/java/run/halo/app/repository/PostCommentRepository.java index 0d24f2598..532d87733 100644 --- a/src/main/java/run/halo/app/repository/PostCommentRepository.java +++ b/src/main/java/run/halo/app/repository/PostCommentRepository.java @@ -6,6 +6,7 @@ import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.lang.NonNull; import run.halo.app.model.entity.PostComment; +import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.projection.CommentChildrenCountProjection; import run.halo.app.model.projection.CommentCountProjection; import run.halo.app.repository.base.BaseCommentRepository; @@ -34,6 +35,25 @@ public interface PostCommentRepository extends BaseCommentRepository countByPostIds(@NonNull Collection postIds); + /** + * Counts comment count by comment status and post id collection. + * + * @param status status must not be null + * @param postsId post id collection must not be null + * @return a list of comment count + */ + @Query( + "select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), " + + "comment.postId) " + + "from PostComment comment " + + "where comment.status = ?1 " + + "and comment.postId in ?2 " + + "group by comment.postId") + @NonNull + @Override + List countByStatusAndPostIds(@NonNull CommentStatus status, + @NonNull Collection postsId); + /** * Finds direct children count by comment ids. * diff --git a/src/main/java/run/halo/app/repository/SheetCommentRepository.java b/src/main/java/run/halo/app/repository/SheetCommentRepository.java index aacc22fe6..368dee736 100644 --- a/src/main/java/run/halo/app/repository/SheetCommentRepository.java +++ b/src/main/java/run/halo/app/repository/SheetCommentRepository.java @@ -5,6 +5,7 @@ import java.util.List; import org.springframework.data.jpa.repository.Query; import org.springframework.lang.NonNull; import run.halo.app.model.entity.SheetComment; +import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.projection.CommentChildrenCountProjection; import run.halo.app.model.projection.CommentCountProjection; import run.halo.app.repository.base.BaseCommentRepository; @@ -33,6 +34,25 @@ public interface SheetCommentRepository extends BaseCommentRepository countByPostIds(@NonNull Collection sheetIds); + /** + * Counts comment count by comment status and sheet id collection. + * + * @param status status must not be null + * @param sheetsId sheet id collection must not be null + * @return a list of comment count + */ + @Query( + "select new run.halo.app.model.projection.CommentCountProjection(count(comment.id), " + + "comment.postId) " + + "from SheetComment comment " + + "where comment.status = ?1 " + + "and comment.postId in ?2 " + + "group by comment.postId") + @NonNull + @Override + List countByStatusAndPostIds(@NonNull CommentStatus status, + @NonNull Collection sheetsId); + /** * Finds direct children count by comment ids. * diff --git a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java index fbf3604b1..aeb429813 100644 --- a/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java +++ b/src/main/java/run/halo/app/repository/base/BaseCommentRepository.java @@ -221,6 +221,7 @@ public interface BaseCommentRepository + "where comment.parentId in ?1 " + "group by comment.parentId") @NonNull + @Deprecated List findDirectChildrenCount( @NonNull Collection commentIds);