Search in sources :

Example 16 with BadRequestAlertException

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

Aggregations

Timed (com.codahale.metrics.annotation.Timed)16 BadRequestAlertException (io.github.jhipster.sample.web.rest.errors.BadRequestAlertException)16 URI (java.net.URI)16 User (io.github.jhipster.sample.domain.User)6 EmailAlreadyUsedException (io.github.jhipster.sample.web.rest.errors.EmailAlreadyUsedException)6 LoginAlreadyUsedException (io.github.jhipster.sample.web.rest.errors.LoginAlreadyUsedException)6 Secured (org.springframework.security.access.annotation.Secured)6 BankAccount (io.github.jhipster.sample.domain.BankAccount)4 Label (io.github.jhipster.sample.domain.Label)3 Operation (io.github.jhipster.sample.domain.Operation)3 BankAccountDTO (io.github.jhipster.sample.service.dto.BankAccountDTO)1 LabelDTO (io.github.jhipster.sample.service.dto.LabelDTO)1 OperationDTO (io.github.jhipster.sample.service.dto.OperationDTO)1