package com.openisle.repository; import com.openisle.model.Post; import com.openisle.model.PostStatus; import com.openisle.model.User; import com.openisle.model.Category; import com.openisle.model.Tag; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; import java.time.LocalDateTime; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; public interface PostRepository extends JpaRepository { List findByStatus(PostStatus status); List findByStatus(PostStatus status, Pageable pageable); List findByStatusOrderByViewsDesc(PostStatus status); List findByStatusOrderByViewsDesc(PostStatus status, Pageable pageable); List findByAuthorAndStatusOrderByCreatedAtDesc(User author, PostStatus status, Pageable pageable); List findByCategoryInAndStatus(List categories, PostStatus status); List findByCategoryInAndStatus(List categories, PostStatus status, Pageable pageable); List findDistinctByTagsInAndStatus(List tags, PostStatus status); List findDistinctByTagsInAndStatus(List tags, PostStatus status, Pageable pageable); List findDistinctByCategoryInAndTagsInAndStatus(List categories, List tags, PostStatus status); List findDistinctByCategoryInAndTagsInAndStatus(List categories, List tags, PostStatus status, Pageable pageable); List findByCategoryInAndStatusOrderByViewsDesc(List categories, PostStatus status); List findByCategoryInAndStatusOrderByViewsDesc(List categories, PostStatus status, Pageable pageable); List findDistinctByTagsInAndStatusOrderByViewsDesc(List tags, PostStatus status); List findDistinctByTagsInAndStatusOrderByViewsDesc(List tags, PostStatus status, Pageable pageable); List findDistinctByCategoryInAndTagsInAndStatusOrderByViewsDesc(List categories, List tags, PostStatus status); List findDistinctByCategoryInAndTagsInAndStatusOrderByViewsDesc(List categories, List tags, PostStatus status, Pageable pageable); List findByTitleContainingIgnoreCaseOrContentContainingIgnoreCaseAndStatus(String titleKeyword, String contentKeyword, PostStatus status); List findByContentContainingIgnoreCaseAndStatus(String keyword, PostStatus status); List findByTitleContainingIgnoreCaseAndStatus(String keyword, PostStatus status); @Query("SELECT MAX(p.createdAt) FROM Post p WHERE p.author.username = :username AND p.status = com.openisle.model.PostStatus.PUBLISHED") LocalDateTime findLastPostTime(@Param("username") String username); @Query("SELECT SUM(p.views) FROM Post p WHERE p.author.username = :username AND p.status = com.openisle.model.PostStatus.PUBLISHED") Long sumViews(@Param("username") String username); }