Add post listing filters and pagination

This commit is contained in:
Tim
2025-07-01 16:03:07 +08:00
parent de463e0884
commit d9e61ac756
4 changed files with 39 additions and 4 deletions

View File

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