Add ranking filtering by tags and categories

This commit is contained in:
Tim
2025-07-09 21:13:50 +08:00
parent 57a8bfeac6
commit e0efca7edf
5 changed files with 113 additions and 6 deletions

View File

@@ -86,9 +86,22 @@ public class PostController {
}
@GetMapping("/ranking")
public List<PostDto> rankingPosts(@RequestParam(value = "page", required = false) Integer page,
public List<PostDto> rankingPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
@RequestParam(value = "tagId", required = false) Long tagId,
@RequestParam(value = "tagIds", required = false) List<Long> tagIds,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
return postService.listPostsByViews(page, pageSize)
List<Long> ids = categoryIds;
if (categoryId != null) {
ids = java.util.List.of(categoryId);
}
List<Long> tids = tagIds;
if (tagId != null) {
tids = java.util.List.of(tagId);
}
return postService.listPostsByViews(ids, tids, page, pageSize)
.stream().map(this::toDto).collect(Collectors.toList());
}