use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-dto by jhipster.
the class LabelResource method createLabel.
/**
* POST /labels : Create a new label.
*
* @param labelDTO the labelDTO to create
* @return the ResponseEntity with status 201 (Created) and with body the new labelDTO, or with status 400 (Bad Request) if the label has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/labels")
@Timed
public ResponseEntity<LabelDTO> createLabel(@Valid @RequestBody LabelDTO labelDTO) throws URISyntaxException {
log.debug("REST request to save Label : {}", labelDTO);
if (labelDTO.getId() != null) {
throw new BadRequestAlertException("A new label cannot already have an ID", ENTITY_NAME, "idexists");
}
Label label = labelMapper.toEntity(labelDTO);
label = labelRepository.save(label);
LabelDTO result = labelMapper.toDto(label);
return ResponseEntity.created(new URI("/api/labels/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Aggregations