mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 06:50:53 +08:00
Add post listing filters and pagination
This commit is contained in:
@@ -49,8 +49,16 @@ public class PostController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<PostDto> listPosts() {
|
||||
return postService.listPosts().stream().map(this::toDto).collect(Collectors.toList());
|
||||
public List<PostDto> listPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||
@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
List<Long> ids = categoryIds;
|
||||
if (categoryId != null) {
|
||||
ids = java.util.List.of(categoryId);
|
||||
}
|
||||
return postService.listPostsByCategories(ids, page, pageSize)
|
||||
.stream().map(this::toDto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private PostDto toDto(Post post) {
|
||||
|
||||
Reference in New Issue
Block a user