Ejemplo n.º 1
0
  @RequestMapping(
      value = "",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<?> list() {

    return new ResponseEntity<List<Product>>(service.listAll(), HttpStatus.OK);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }