Beispiel #1
0
 /** GET /books -> get all the books. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<List<Book>> getAllBooks(Pageable pageable) throws URISyntaxException {
   Page<Book> page = bookRepository.findAll(pageable);
   HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/books");
   return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
 }
Beispiel #2
0
 /** GET /books/:id -> get the "id" book. */
 @RequestMapping(
     value = "/books/{id}",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> getBook(@PathVariable Long id) {
   log.debug("REST request to get Book : {}", id);
   return Optional.ofNullable(bookRepository.findOne(id))
       .map(book -> new ResponseEntity<>(book, HttpStatus.OK))
       .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
 }
Beispiel #3
0
 /** DELETE /books/:id -> delete the "id" book. */
 @RequestMapping(
     value = "/books/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteBook(@PathVariable Long id) {
   log.debug("REST request to delete Book : {}", id);
   bookRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("book", id.toString()))
       .build();
 }
Beispiel #4
0
 /** PUT /books -> Updates an existing book. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> updateBook(@RequestBody Book book) throws URISyntaxException {
   log.debug("REST request to update Book : {}", book);
   if (book.getId() == null) {
     return createBook(book);
   }
   Book result = bookRepository.save(book);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityUpdateAlert("book", book.getId().toString()))
       .body(result);
 }
Beispiel #5
0
 /** POST /books -> Create a new book. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.POST,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> createBook(@RequestBody Book book) throws URISyntaxException {
   log.debug("REST request to save Book : {}", book);
   if (book.getId() != null) {
     return ResponseEntity.badRequest()
         .header("Failure", "A new book cannot already have an ID")
         .body(null);
   }
   Book result = bookRepository.save(book);
   return ResponseEntity.created(new URI("/api/books/" + result.getId()))
       .headers(HeaderUtil.createEntityCreationAlert("book", result.getId().toString()))
       .body(result);
 }