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