Search in sources :

Example 11 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Agent(com.arnaugarcia.uplace.domain.Agent) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 12 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Company(com.arnaugarcia.uplace.domain.Company) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 13 with BadRequestAlertException

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);
    }
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Notification(com.arnaugarcia.uplace.domain.Notification) Timed(com.codahale.metrics.annotation.Timed)

Example 14 with BadRequestAlertException

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);
    }
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User) LoginAlreadyUsedException(com.arnaugarcia.uplace.web.rest.errors.LoginAlreadyUsedException) URI(java.net.URI) EmailAlreadyUsedException(com.arnaugarcia.uplace.web.rest.errors.EmailAlreadyUsedException) Secured(org.springframework.security.access.annotation.Secured) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)14 Timed (com.codahale.metrics.annotation.Timed)9 URI (java.net.URI)8 User (com.arnaugarcia.uplace.domain.User)6 Notification (com.arnaugarcia.uplace.domain.Notification)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Agent (com.arnaugarcia.uplace.domain.Agent)1 Company (com.arnaugarcia.uplace.domain.Company)1 Location (com.arnaugarcia.uplace.domain.Location)1 Photo (com.arnaugarcia.uplace.domain.Photo)1 RealEstate (com.arnaugarcia.uplace.domain.RealEstate)1 LocationDTO (com.arnaugarcia.uplace.service.dto.LocationDTO)1 EmailAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.LoginAlreadyUsedException)1 Secured (org.springframework.security.access.annotation.Secured)1