use of io.github.jhipster.sample.web.rest.errors.BadRequestAlertException in project jhipster-sample-app-websocket by jhipster.
the class UserResource method createUser.
/**
* POST /users : Creates a new user.
* <p>
* Creates a new user if the login and email are not already used, and sends an
* mail with an activation link.
* The user needs to be activated on creation.
*
* @param userDTO the user to create
* @return the ResponseEntity with status 201 (Created) and with body the new user, or with status 400 (Bad Request) if the login or email is already in use
* @throws URISyntaxException if the Location URI syntax is incorrect
* @throws BadRequestAlertException 400 (Bad Request) if the login or email is already in use
*/
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<User> createUser(@Valid @RequestBody UserDTO userDTO) throws URISyntaxException {
log.debug("REST request to save User : {}", userDTO);
if (userDTO.getId() != null) {
throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists");
// Lowercase the user login before comparing with database
} else if (userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()).isPresent()) {
throw new LoginAlreadyUsedException();
} else if (userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).isPresent()) {
throw new EmailAlreadyUsedException();
} else {
User newUser = userService.createUser(userDTO);
mailService.sendCreationEmail(newUser);
return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin())).headers(HeaderUtil.createAlert("userManagement.created", newUser.getLogin())).body(newUser);
}
}
use of io.github.jhipster.sample.web.rest.errors.BadRequestAlertException in project jhipster-sample-app-hazelcast by jhipster.
the class BankAccountResource method createBankAccount.
/**
* POST /bank-accounts : Create a new bankAccount.
*
* @param bankAccount the bankAccount to create
* @return the ResponseEntity with status 201 (Created) and with body the new bankAccount, or with status 400 (Bad Request) if the bankAccount has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/bank-accounts")
@Timed
public ResponseEntity<BankAccount> createBankAccount(@Valid @RequestBody BankAccount bankAccount) throws URISyntaxException {
log.debug("REST request to save BankAccount : {}", bankAccount);
if (bankAccount.getId() != null) {
throw new BadRequestAlertException("A new bankAccount cannot already have an ID", ENTITY_NAME, "idexists");
}
BankAccount result = bankAccountRepository.save(bankAccount);
return ResponseEntity.created(new URI("/api/bank-accounts/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of io.github.jhipster.sample.web.rest.errors.BadRequestAlertException in project jhipster-sample-app-elasticsearch by jhipster.
the class BankAccountResource method createBankAccount.
/**
* POST /bank-accounts : Create a new bankAccount.
*
* @param bankAccount the bankAccount to create
* @return the ResponseEntity with status 201 (Created) and with body the new bankAccount, or with status 400 (Bad Request) if the bankAccount has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/bank-accounts")
@Timed
public ResponseEntity<BankAccount> createBankAccount(@Valid @RequestBody BankAccount bankAccount) throws URISyntaxException {
log.debug("REST request to save BankAccount : {}", bankAccount);
if (bankAccount.getId() != null) {
throw new BadRequestAlertException("A new bankAccount cannot already have an ID", ENTITY_NAME, "idexists");
}
BankAccount result = bankAccountRepository.save(bankAccount);
bankAccountSearchRepository.save(result);
return ResponseEntity.created(new URI("/api/bank-accounts/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of io.github.jhipster.sample.web.rest.errors.BadRequestAlertException in project jhipster-sample-app-dto by jhipster.
the class BankAccountResource method createBankAccount.
/**
* POST /bank-accounts : Create a new bankAccount.
*
* @param bankAccountDTO the bankAccountDTO to create
* @return the ResponseEntity with status 201 (Created) and with body the new bankAccountDTO, or with status 400 (Bad Request) if the bankAccount has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/bank-accounts")
@Timed
public ResponseEntity<BankAccountDTO> createBankAccount(@Valid @RequestBody BankAccountDTO bankAccountDTO) throws URISyntaxException {
log.debug("REST request to save BankAccount : {}", bankAccountDTO);
if (bankAccountDTO.getId() != null) {
throw new BadRequestAlertException("A new bankAccount cannot already have an ID", ENTITY_NAME, "idexists");
}
BankAccount bankAccount = bankAccountMapper.toEntity(bankAccountDTO);
bankAccount = bankAccountRepository.save(bankAccount);
BankAccountDTO result = bankAccountMapper.toDto(bankAccount);
return ResponseEntity.created(new URI("/api/bank-accounts/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of io.github.jhipster.sample.web.rest.errors.BadRequestAlertException 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);
}
Aggregations