mirror of https://github.com/halo-dev/halo
👽 添加小程序返回所有文章Api
parent
10b802b3a9
commit
2db77321e0
|
@ -130,6 +130,29 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||
@Query(value = "SELECT YEAR(post_date) AS YEAR,COUNT(*) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post' GROUP BY YEAR(post_date) ORDER BY YEAR DESC", nativeQuery = true)
|
||||
List<Object[]> findPostGroupByYear();
|
||||
|
||||
|
||||
/**
|
||||
* @Author Aquan
|
||||
* @Description 查询文章归档信息 查询所有文章
|
||||
* @Date 2019.1.4 11:19
|
||||
* @Param
|
||||
* @return List
|
||||
**/
|
||||
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' ORDER BY post_date DESC", nativeQuery = true)
|
||||
List<Post> findAllPost();
|
||||
|
||||
/**
|
||||
* @Author Aquan
|
||||
* @Description 查询文章总数
|
||||
* @Date 2019.1.4 15:03
|
||||
* @Param
|
||||
* @return Integer
|
||||
**/
|
||||
@Query(value = "SELECT count(1) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post'", nativeQuery = true)
|
||||
Integer totalAllPostCount();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
|
|
|
@ -161,6 +161,16 @@ public interface PostService {
|
|||
*/
|
||||
List<Archive> findPostGroupByYear();
|
||||
|
||||
/**
|
||||
* @Author Aquan
|
||||
* @Description 查询归档信息 查看所有文章
|
||||
* @Date 2019.1.4 11:14
|
||||
* @Param
|
||||
* @return List
|
||||
**/
|
||||
List<Archive> findAllPost();
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
|
|
|
@ -286,6 +286,29 @@ public class PostServiceImpl implements PostService {
|
|||
return archives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author Aquan
|
||||
* @Description 查询归档信息 返回所有文章
|
||||
* @Date 2019.1.4 11:16
|
||||
* @Param
|
||||
* @return List
|
||||
**/
|
||||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'")
|
||||
public List<Archive> findAllPost() {
|
||||
final List<Post> posts = postRepository.findAllPost();
|
||||
final Integer count = postRepository.totalAllPostCount();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
archive = new Archive();
|
||||
archive.setCount(String.valueOf(count));
|
||||
archive.setPosts(posts);
|
||||
archives.add(archive);
|
||||
|
||||
return archives;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据年份和月份查询文章
|
||||
*
|
||||
|
|
|
@ -135,4 +135,23 @@ public class ApiArchivesController {
|
|||
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author Aquan
|
||||
* @Description 返回所有文章
|
||||
* @Date 2019.1.4 11:06
|
||||
* @Param
|
||||
* @return JsonResult
|
||||
**/
|
||||
@GetMapping(value = "/all")
|
||||
public JsonResult archivesAllPost() {
|
||||
final List<Archive> archive = postService.findAllPost();
|
||||
if (null != archive && archive.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), archive);
|
||||
} else {
|
||||
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue