Search in sources :

Example 21 with Label

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);
}
Also used : BadRequestAlertException(io.github.jhipster.sample.web.rest.errors.BadRequestAlertException) Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Label (io.github.jhipster.sample.domain.Label)21 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 Transactional (org.springframework.transaction.annotation.Transactional)12 LabelDTO (io.github.jhipster.sample.service.dto.LabelDTO)7 Timed (com.codahale.metrics.annotation.Timed)6 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)3 URI (java.net.URI)3