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