Search in sources :

Example 1 with Label

use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-dto by jhipster.

the class LabelResource method updateLabel.

/**
 * PUT  /labels : Updates an existing label.
 *
 * @param labelDTO the labelDTO to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated labelDTO,
 * or with status 400 (Bad Request) if the labelDTO is not valid,
 * or with status 500 (Internal Server Error) if the labelDTO couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/labels")
@Timed
public ResponseEntity<LabelDTO> updateLabel(@Valid @RequestBody LabelDTO labelDTO) throws URISyntaxException {
    log.debug("REST request to update Label : {}", labelDTO);
    if (labelDTO.getId() == null) {
        return createLabel(labelDTO);
    }
    Label label = labelMapper.toEntity(labelDTO);
    label = labelRepository.save(label);
    LabelDTO result = labelMapper.toDto(label);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, labelDTO.getId().toString())).body(result);
}
Also used : Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with Label

use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-dto by jhipster.

the class LabelResourceIntTest method updateLabel.

@Test
@Transactional
public void updateLabel() throws Exception {
    // Initialize the database
    labelRepository.saveAndFlush(label);
    int databaseSizeBeforeUpdate = labelRepository.findAll().size();
    // Update the label
    Label updatedLabel = labelRepository.findById(label.getId()).get();
    // Disconnect from session so that the updates on updatedLabel are not directly saved in db
    em.detach(updatedLabel);
    updatedLabel.setLabel(UPDATED_LABEL);
    LabelDTO labelDTO = labelMapper.toDto(updatedLabel);
    restLabelMockMvc.perform(put("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(labelDTO))).andExpect(status().isOk());
    // Validate the Label in the database
    List<Label> labelList = labelRepository.findAll();
    assertThat(labelList).hasSize(databaseSizeBeforeUpdate);
    Label testLabel = labelList.get(labelList.size() - 1);
    assertThat(testLabel.getLabel()).isEqualTo(UPDATED_LABEL);
}
Also used : Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Label

use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-dto by jhipster.

the class LabelResourceIntTest method checkLabelIsRequired.

@Test
@Transactional
public void checkLabelIsRequired() throws Exception {
    int databaseSizeBeforeTest = labelRepository.findAll().size();
    // set the field null
    label.setLabel(null);
    // Create the Label, which fails.
    LabelDTO labelDTO = labelMapper.toDto(label);
    restLabelMockMvc.perform(post("/api/labels").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(labelDTO))).andExpect(status().isBadRequest());
    List<Label> labelList = labelRepository.findAll();
    assertThat(labelList).hasSize(databaseSizeBeforeTest);
}
Also used : Label(io.github.jhipster.sample.domain.Label) LabelDTO(io.github.jhipster.sample.service.dto.LabelDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Label

use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-hazelcast by jhipster.

the class LabelResource method createLabel.

/**
 * 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
 */
@PostMapping("/labels")
@Timed
public ResponseEntity<Label> createLabel(@Valid @RequestBody Label label) throws URISyntaxException {
    log.debug("REST request to save Label : {}", label);
    if (label.getId() != null) {
        throw new BadRequestAlertException("A new label cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Label result = labelRepository.save(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) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Label

use of io.github.jhipster.sample.domain.Label in project jhipster-sample-app-hazelcast by jhipster.

the class LabelResourceIntTest method createEntity.

/**
 * Create an entity for this test.
 *
 * This is a static method, as tests for other entities might also need it,
 * if they test an entity which requires the current entity.
 */
public static Label createEntity(EntityManager em) {
    Label label = new Label();
    label.setLabel(DEFAULT_LABEL);
    return label;
}
Also used : Label(io.github.jhipster.sample.domain.Label)

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