Skip to content

Commit

Permalink
fix: post api search
Browse files Browse the repository at this point in the history
  • Loading branch information
LAPLACE4A committed Nov 4, 2024
1 parent d8f3219 commit b890eee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/kert/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ResponseEntity<Page<Post>> getPosts(
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size) {

Page<Post> posts = postService.searchPosts(search, page, size);
Page<Post> posts = postService.searchPosts(search, page -1, size);
return ResponseEntity.ok(posts);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kert/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private String extractTokenFromRequest(HttpServletRequest request) {

public Page<Post> searchPosts(String search, int page, int size) {
Pageable pageable = PageRequest.of(page, size);
if (search != null && !search.isEmpty()) {
if (search != null && !search.trim().isEmpty()) {
return postRepository.findByTitleContainingOrTagContaining(search, search, pageable);
} else {
return postRepository.findAll(pageable);
Expand Down

0 comments on commit b890eee

Please sign in to comment.