/** DELETE /customers/:id -> delete the "id" customer. */ @RequestMapping( value = "/customers/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public void delete(@PathVariable Long id) { log.debug("REST request to delete Customer : {}", id); customerRepository.delete(id); }
/** GET /customers/:id -> get the "id" customer. */ @RequestMapping( value = "/customers/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Customer> get(@PathVariable Long id) { log.debug("REST request to get Customer : {}", id); return Optional.ofNullable(customerRepository.findOne(id)) .map(customer -> new ResponseEntity<>(customer, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
/** PUT /customers -> Updates an existing customer. */ @RequestMapping( value = "/customers", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Customer> update(@Valid @RequestBody Customer customer) throws URISyntaxException { log.debug("REST request to update Customer : {}", customer); if (customer.getId() == null) { return create(customer); } Customer result = customerRepository.save(customer); return ResponseEntity.ok().body(result); }
/** GET /customers -> get all the customers. */ @RequestMapping( value = "/customers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<List<Customer>> getAll( @RequestParam(value = "page", required = false) Integer offset, @RequestParam(value = "per_page", required = false) Integer limit) throws URISyntaxException { Page<Customer> page = customerRepository.findAll(PaginationUtil.generatePageRequest(offset, limit)); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/customers", offset, limit); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
/** POST /customers -> Create a new customer. */ @RequestMapping( value = "/customers", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Customer> create(@Valid @RequestBody Customer customer) throws URISyntaxException { log.debug("REST request to save Customer : {}", customer); if (customer.getId() != null) { return ResponseEntity.badRequest() .header("Failure", "A new customer cannot already have an ID") .body(null); } Customer result = customerRepository.save(customer); return ResponseEntity.created(new URI("/api/customers/" + customer.getId())).body(result); }