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