예제 #1
0
 /** GET /books/:id -> get the "id" book. */
 @RequestMapping(
     value = "/books/{id}",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> get(@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));
 }
예제 #2
0
 /** DELETE /books/:id -> delete the "id" book. */
 @RequestMapping(
     value = "/books/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> delete(@PathVariable Long id) {
   log.debug("REST request to delete Book : {}", id);
   bookRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("book", id.toString()))
       .build();
 }
예제 #3
0
 /** GET /books -> get all the books. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<List<Book>> getAll(
     @RequestParam(value = "page", required = false) Integer offset,
     @RequestParam(value = "per_page", required = false) Integer limit)
     throws URISyntaxException {
   Page<Book> page = bookRepository.findAll(PaginationUtil.generatePageRequest(offset, limit));
   HttpHeaders headers =
       PaginationUtil.generatePaginationHttpHeaders(page, "/api/books", offset, limit);
   return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
 }
예제 #4
0
 /** PUT /books -> Updates an existing book. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> update(@RequestBody Book book) throws URISyntaxException {
   log.debug("REST request to update Book : {}", book);
   if (book.getId() == null) {
     return create(book);
   }
   Book result = bookRepository.save(book);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityUpdateAlert("book", book.getId().toString()))
       .body(result);
 }
예제 #5
0
 /** POST /books -> Create a new book. */
 @RequestMapping(
     value = "/books",
     method = RequestMethod.POST,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Book> create(@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);
 }