mirror of https://github.com/halo-dev/halo
Add top priority sort at post list in category and tag (#918)
parent
aee79ef7b4
commit
a179f4fc9c
|
@ -57,7 +57,7 @@ public class CategoryController {
|
|||
@GetMapping("{slug}/posts")
|
||||
@ApiOperation("Lists posts by category slug")
|
||||
public Page<BasePostSimpleDTO> listPostsBy(@PathVariable("slug") String slug,
|
||||
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
@PageableDefault(sort = {"topPriority", "updateTime"}, direction = DESC) Pageable pageable) {
|
||||
// Get category by slug
|
||||
Category category = categoryService.getBySlugOfNonNull(slug);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TagController {
|
|||
@GetMapping("{slug}/posts")
|
||||
@ApiOperation("Lists posts by tag slug")
|
||||
public Page<BasePostSimpleDTO> listPostsBy(@PathVariable("slug") String slug,
|
||||
@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
@PageableDefault(sort = {"topPriority", "updateTime"}, direction = DESC) Pageable pageable) {
|
||||
// Get tag by slug
|
||||
Tag tag = tagService.getBySlugOfNonNull(slug);
|
||||
|
||||
|
|
|
@ -69,7 +69,9 @@ public class CategoryModel {
|
|||
final Category category = categoryService.getBySlugOfNonNull(slug);
|
||||
CategoryDTO categoryDTO = categoryService.convertTo(category);
|
||||
|
||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getArchivesPageSize(), Sort.by(DESC, "createTime"));
|
||||
final Pageable pageable = PageRequest.of(page - 1,
|
||||
optionService.getArchivesPageSize(),
|
||||
Sort.by(DESC, "topPriority", "createTime"));
|
||||
Page<Post> postPage = postCategoryService.pagePostBy(category.getId(), PostStatus.PUBLISHED, pageable);
|
||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||
|
||||
|
|
|
@ -29,4 +29,8 @@ public class BasePostSimpleDTO extends BasePostMinimalDTO {
|
|||
private Integer topPriority;
|
||||
|
||||
private Long likes;
|
||||
|
||||
public boolean isTopped() {
|
||||
return this.topPriority != null && this.topPriority > 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue