mirror of https://github.com/bvn13/VoidForum.git
50 lines
2.0 KiB
Java
50 lines
2.0 KiB
Java
package ru.bvn13.voidforum.repositories;
|
|
|
|
import ru.bvn13.voidforum.models.Post;
|
|
import ru.bvn13.voidforum.models.User;
|
|
import ru.bvn13.voidforum.models.support.PostStatus;
|
|
import ru.bvn13.voidforum.models.support.PostType;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
import org.springframework.data.jpa.repository.Query;
|
|
import org.springframework.data.repository.query.Param;
|
|
import org.springframework.stereotype.Repository;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* bvn13 <mail4bvn@gmail.com>
|
|
*/
|
|
@Repository
|
|
@Transactional
|
|
public interface PostRepository extends JpaRepository<Post, Long> {
|
|
Post findByPermalinkAndPostStatus(String permalink, PostStatus postStatus);
|
|
|
|
Post findByIdAndPostStatus(Long postId, PostStatus postStatus);
|
|
|
|
Page<Post> findAllByPostType(PostType postType, Pageable pageRequest);
|
|
|
|
Page<Post> findAllByPostTypeAndPostStatus(PostType postType, PostStatus postStatus, Pageable pageRequest);
|
|
|
|
Page<Post> findAllByPostTypeAndPostStatusAndDeletedMarkAndCensored(PostType postType, PostStatus postStatus, Boolean deletedMark, Boolean censored, Pageable pageRequest);
|
|
|
|
List<Post> findAllByPostTypeAndPostStatus(PostType postType, PostStatus postStatus);
|
|
|
|
@Query("SELECT p FROM Post p INNER JOIN p.tags t WHERE t.name = :tag")
|
|
Page<Post> findByTag(@Param("tag") String tag, Pageable pageable);
|
|
|
|
@Query("SELECT t.name, count(p) as tag_count from Post p " +
|
|
"INNER JOIN p.tags t " +
|
|
"WHERE p.postStatus = :status " +
|
|
"GROUP BY t.id " +
|
|
"ORDER BY tag_count DESC")
|
|
List<Object[]> countPostsByTags(@Param("status") PostStatus status);
|
|
|
|
Page<Post> findAllByPostTypeAndPostStatusAndDeletedMark(PostType postType, PostStatus postStatus, Boolean deletedMark, Pageable pageRequest);
|
|
|
|
Page<Post> findAllByUser(User user, Pageable pageRequest);
|
|
}
|
|
|