/** 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(); }
/** 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); }
/** 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); }