Пример #1
0
  @RequestMapping(
      value = "",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<?> list() {

    return new ResponseEntity<List<Product>>(service.listAll(), HttpStatus.OK);
  }
Пример #2
0
  @RequestMapping(
      value = "/{id}",
      method = RequestMethod.DELETE,
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<?> delete(@PathVariable("id") int id) {

    service.delete(new Product(id));

    return new ResponseEntity<Product>(HttpStatus.OK);
  }
Пример #3
0
  @RequestMapping(
      value = "",
      method = RequestMethod.PATCH,
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<?> update(@RequestBody Product product) {

    service.update(product);

    return new ResponseEntity<Product>(HttpStatus.OK);
  }
Пример #4
0
  @RequestMapping(
      value = "/remove/{id}",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<?> list(@PathVariable("id") int id) {

    HttpStatus status = HttpStatus.NOT_FOUND;

    if (service.canRemove(id)) {
      status = HttpStatus.OK;
    }

    return new ResponseEntity<Product>(status);
  }