Esempio n. 1
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);
 }
Esempio n. 2
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);
 }