package cn.reghao.tnb.search.app.blog.db.repository;

import cn.reghao.tnb.search.app.blog.model.po.ArticleView;
import cn.reghao.tnb.search.app.blog.model.vo.ArticleCount;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author reghao
 * @date 2024-02-05 14:29:19
 */
public interface ArticleViewRepository extends JpaRepository<ArticleView, Integer> {
    ArticleView findArticleViewByArticleIdAndSessionId(String articleId, String sessionId);
    int countByArticleId(String articleId);

    @Query("select new cn.reghao.tnb.search.app.blog.model.vo.ArticleCount(view.articleId, count(view))\n" +
            "from ArticleView view\n" +
            "group by view.articleId \n" +
            "order by count(view) desc")
    List<ArticleCount> findViewCountByGroup(Pageable pageable);
}
