Skip to content

Commit 5ef2af1

Browse files
committed
feat: add validation to page
1 parent a8b74f0 commit 5ef2af1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/org/poolc/api/book/client/NaverBookClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public List<BookApiResponse> searchBooks(String query, int page) throws XMLParse
4242
String url = new StringBuilder(this.url)
4343
.append("?query=").append(query)
4444
.append("&display=").append(PAGE_SIZE)
45-
.append("&start=").append((page - 1) * PAGE_SIZE + 1)
45+
.append("&start=").append(page * PAGE_SIZE + 1)
4646
.toString();
4747

4848
String xmlResponse = restTemplate.exchange(url, HttpMethod.GET, entity, String.class).getBody();

src/main/java/org/poolc/api/book/controller/BookController.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.web.bind.annotation.*;
1313

1414
import javax.validation.Valid;
15+
import javax.validation.constraints.Min;
1516

1617
@RestController
1718
@RequestMapping("/book")
@@ -22,7 +23,8 @@ public class BookController {
2223
private final BookService bookService;
2324

2425
@GetMapping("/search")
25-
public ResponseEntity<?> searchBooks(@RequestParam String query, @RequestParam Integer page) {
26+
public ResponseEntity<?> searchBooks(@RequestParam String query,
27+
@RequestParam(value = "page", defaultValue = "0") @Min(0) Integer page) {
2628
try {
2729
return new ResponseEntity<>(bookClient.searchBooks(query, page), HttpStatus.OK);
2830
} catch (Exception e) {
@@ -31,7 +33,7 @@ public ResponseEntity<?> searchBooks(@RequestParam String query, @RequestParam I
3133
}
3234

3335
@GetMapping("/all")
34-
public ResponseEntity<?> getAllBooks(@RequestParam Integer page) {
36+
public ResponseEntity<?> getAllBooks(@RequestParam(value = "page", defaultValue = "0") @Min(0) Integer page) {
3537
try {
3638
return new ResponseEntity<>(bookService.getAllBooks(page), HttpStatus.OK);
3739
} catch (Exception e) {

0 commit comments

Comments
 (0)