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