use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class AgentResource method createAgent.
/**
* POST /agents : Create a new agent.
*
* @param agent the agent to create
* @return the ResponseEntity with status 201 (Created) and with body the new agent, or with status 400 (Bad Request) if the agent has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/agents")
@Timed
public ResponseEntity<Agent> createAgent(@Valid @RequestBody Agent agent) throws URISyntaxException {
log.debug("REST request to save Agent : {}", agent);
if (agent.getId() != null) {
throw new BadRequestAlertException("A new agent cannot already have an ID", ENTITY_NAME, "idexists");
}
Agent result = agentService.save(agent);
return ResponseEntity.created(new URI("/api/agents/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class CompanyResource method createCompany.
/**
* POST /companies : Create a new company.
*
* @param company the company to create
* @return the ResponseEntity with status 201 (Created) and with body the new company, or with status 400 (Bad Request) if the company has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/company")
@Timed
public ResponseEntity<Company> createCompany(@RequestBody Company company) throws URISyntaxException {
log.debug("REST request to save Company : {}", company);
if (company.getId() != null) {
throw new BadRequestAlertException("A new company cannot already have an ID", ENTITY_NAME, "idexists");
}
Company result = companyService.save(company);
return ResponseEntity.created(new URI("/api/companies/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class NotificationResource method deleteNotification.
/**
* GET /notifications/read
* @return the ResponseEntity with status 200 (OK) and with body the notifications updated, or with status 404 (Not Found)
*/
/*@PutMapping("/notifications/read")
@Timed
public List<Notification> markNotificationsAsRead(@RequestParam List<Notification> notificationsList) {
log.debug("REST request to mark all the Notifications as read : {}");
return notificationService.markAs(notificationsList, true);
}*/
/**
* GET /notifications/unread
* @return the List<Notification> with status 200 (OK) and with body the notifications updated, or with status 404 (Not Found)
*/
/*@GetMapping("/notifications/unread")
@Timed
public List<Notification> markNotificationsAsUnRead(@RequestParam List<Notification> notificationsList) {
log.debug("REST request to mark all the Notifications as unread : {}");
return notificationService.markAs(notificationsList, false);
}*/
/**
* DELETE /notifications/:id : delete the "id" notification.
*
* @param id the id of the notification to delete
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("/notifications/{id}")
@Timed
public ResponseEntity<Void> deleteNotification(@PathVariable Long id) {
log.debug("REST request to delete Notification : {}", id);
Notification notification = notificationService.findOneByType(NotificationType.NOTIFICATION, id);
if (notification != null) {
notificationService.delete(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
} else {
throw new BadRequestAlertException("The requested notification doesn't exists", ENTITY_NAME, ErrorConstants.ERR_BAD_ID);
}
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
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);
}
}
Aggregations