/** * SEARCH /_search/labels?query=:query : search for the label corresponding to the query. * * @param query the query of the label search * @return the result of the search */ @RequestMapping( value = "/_search/labels", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public List<Label> searchLabels(@RequestParam String query) { log.debug("REST request to search Labels for query {}", query); return StreamSupport.stream( labelSearchRepository.search(queryStringQuery(query)).spliterator(), false) .collect(Collectors.toList()); }
/** * DELETE /labels/:id : delete the "id" label. * * @param id the id of the label to delete * @return the ResponseEntity with status 200 (OK) */ @RequestMapping( value = "/labels/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Void> deleteLabel(@PathVariable Long id) { log.debug("REST request to delete Label : {}", id); labelRepository.delete(id); labelSearchRepository.delete(id); return ResponseEntity.ok() .headers(HeaderUtil.createEntityDeletionAlert("label", id.toString())) .build(); }
/** * PUT /labels : Updates an existing label. * * @param label the label to update * @return the ResponseEntity with status 200 (OK) and with body the updated label, or with status * 400 (Bad Request) if the label is not valid, or with status 500 (Internal Server Error) if * the label couldnt be updated * @throws URISyntaxException if the Location URI syntax is incorrect */ @RequestMapping( value = "/labels", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Label> updateLabel(@Valid @RequestBody Label label) throws URISyntaxException { log.debug("REST request to update Label : {}", label); if (label.getId() == null) { return createLabel(label); } Label result = labelRepository.save(label); labelSearchRepository.save(result); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert("label", label.getId().toString())) .body(result); }
/** * POST /labels : Create a new label. * * @param label the label to create * @return the ResponseEntity with status 201 (Created) and with body the new label, or with * status 400 (Bad Request) if the label has already an ID * @throws URISyntaxException if the Location URI syntax is incorrect */ @RequestMapping( value = "/labels", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Label> createLabel(@Valid @RequestBody Label label) throws URISyntaxException { log.debug("REST request to save Label : {}", label); if (label.getId() != null) { return ResponseEntity.badRequest() .headers( HeaderUtil.createFailureAlert( "label", "idexists", "A new label cannot already have an ID")) .body(null); } Label result = labelRepository.save(label); labelSearchRepository.save(result); return ResponseEntity.created(new URI("/api/labels/" + result.getId())) .headers(HeaderUtil.createEntityCreationAlert("label", result.getId().toString())) .body(result); }