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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations