From b890eeed0cdb03b3684ccb6457afad9afb8ef8d7 Mon Sep 17 00:00:00 2001 From: LAPLACE4A Date: Mon, 4 Nov 2024 17:37:26 +0900 Subject: [PATCH] fix: post api search --- src/main/java/com/kert/controller/PostController.java | 2 +- src/main/java/com/kert/service/PostService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kert/controller/PostController.java b/src/main/java/com/kert/controller/PostController.java index 6b81ad8..58155c5 100644 --- a/src/main/java/com/kert/controller/PostController.java +++ b/src/main/java/com/kert/controller/PostController.java @@ -27,7 +27,7 @@ public ResponseEntity> getPosts( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) { - Page posts = postService.searchPosts(search, page, size); + Page posts = postService.searchPosts(search, page -1, size); return ResponseEntity.ok(posts); } diff --git a/src/main/java/com/kert/service/PostService.java b/src/main/java/com/kert/service/PostService.java index 8430799..038a326 100644 --- a/src/main/java/com/kert/service/PostService.java +++ b/src/main/java/com/kert/service/PostService.java @@ -41,7 +41,7 @@ private String extractTokenFromRequest(HttpServletRequest request) { public Page 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);