Skip to content

Commit

Permalink
feat: add validation to page
Browse files Browse the repository at this point in the history
  • Loading branch information
becooq81 committed Dec 3, 2024
1 parent a8b74f0 commit 5ef2af1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public List<BookApiResponse> searchBooks(String query, int page) throws XMLParse
String url = new StringBuilder(this.url)
.append("?query=").append(query)
.append("&display=").append(PAGE_SIZE)
.append("&start=").append((page - 1) * PAGE_SIZE + 1)
.append("&start=").append(page * PAGE_SIZE + 1)
.toString();

String xmlResponse = restTemplate.exchange(url, HttpMethod.GET, entity, String.class).getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;

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

@GetMapping("/search")
public ResponseEntity<?> searchBooks(@RequestParam String query, @RequestParam Integer page) {
public ResponseEntity<?> searchBooks(@RequestParam String query,
@RequestParam(value = "page", defaultValue = "0") @Min(0) Integer page) {
try {
return new ResponseEntity<>(bookClient.searchBooks(query, page), HttpStatus.OK);
} catch (Exception e) {
Expand All @@ -31,7 +33,7 @@ public ResponseEntity<?> searchBooks(@RequestParam String query, @RequestParam I
}

@GetMapping("/all")
public ResponseEntity<?> getAllBooks(@RequestParam Integer page) {
public ResponseEntity<?> getAllBooks(@RequestParam(value = "page", defaultValue = "0") @Min(0) Integer page) {
try {
return new ResponseEntity<>(bookService.getAllBooks(page), HttpStatus.OK);
} catch (Exception e) {
Expand Down

0 comments on commit 5ef2af1

Please sign in to comment.