Add top priority sort at post list in category and tag (#918)

pull/921/head
John Niang 2020-06-16 14:37:43 +08:00 committed by GitHub
parent aee79ef7b4
commit a179f4fc9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
}