Search in sources :

Example 1 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationService method delete.

/*
     * Delete the notification by id.
     *
     * @param id the id of the entity
     */
public void delete(Long id) {
    log.debug("Request to delete Notification : {}", id);
    Notification notification = notificationRepository.findOne(id);
    User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
    // If the notification.user does not match and isn't admin... error
    if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
        throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
    }
    notificationRepository.delete(id);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) User(com.arnaugarcia.uplace.domain.User) Notification(com.arnaugarcia.uplace.domain.Notification)

Example 2 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class LocationResource method createLocation.

/**
 * POST  /locations : Create a new location.
 *
 * @param locationDTO the locationDTO to create
 * @return the ResponseEntity with status 201 (Created) and with body the new locationDTO, or with status 400 (Bad Request) if the location has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/locations")
@Timed
public ResponseEntity<LocationDTO> createLocation(@RequestBody LocationDTO locationDTO) throws URISyntaxException {
    log.debug("REST request to save Location : {}", locationDTO);
    if (locationDTO.getId() != null) {
        throw new BadRequestAlertException("A new location cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Location location = locationMapper.toEntity(locationDTO);
    location = locationRepository.save(location);
    LocationDTO result = locationMapper.toDto(location);
    return ResponseEntity.created(new URI("/api/locations/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) URI(java.net.URI) LocationDTO(com.arnaugarcia.uplace.service.dto.LocationDTO) Location(com.arnaugarcia.uplace.domain.Location) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class PhotoResource method createPhoto.

/**
 * POST  /photos : Create a new photo.
 *
 * @param photo the photo to create
 * @return the ResponseEntity with status 201 (Created) and with body the new photo, or with status 400 (Bad Request) if the photo has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/photos")
@Timed
public ResponseEntity<Photo> createPhoto(@Valid @RequestBody Photo photo) throws URISyntaxException {
    log.debug("REST request to save Photo : {}", photo);
    if (photo.getId() != null) {
        throw new BadRequestAlertException("A new photo cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Photo result = photoRepository.save(photo);
    return ResponseEntity.created(new URI("/api/photos/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Photo(com.arnaugarcia.uplace.domain.Photo) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class PropertyResource method createProperty.

/**
 * POST  /properties : Create a new property.
 *
 * @param property the property to create
 * @return the ResponseEntity with status 201 (Created) and with body the new property, or with status 400 (Bad Request) if the property has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/properties")
@Timed
public ResponseEntity<T> createProperty(@Valid @RequestBody T property) throws URISyntaxException {
    log.debug("REST request to save Property : {}", property);
    if (property.getReference() != null) {
        throw new BadRequestAlertException("A new property cannot already have a Reference", "PROPERTY", ErrorConstants.ERR_BAD_REFERENCE);
    }
    // TODO: Implement DTOS in order to validate Entity
    T result = propertyService.save(property);
    return ResponseEntity.created(new URI("/api/properties/" + result.getReference())).headers(HeaderUtil.createEntityCreationAlert(property.getReference(), result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with BadRequestAlertException

use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.

the class NotificationResource method createNotification.

/**
 * POST  /notifications : Create a new notification.
 *
 * @param notification the notification to create
 * @return the ResponseEntity with status 201 (Created) and with body the new notification, or with status 400 (Bad Request) if the notification has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/notifications")
@Timed
public ResponseEntity<Notification> createNotification(@Valid @RequestBody Notification notification) throws URISyntaxException {
    log.debug("REST request to save Notification : {}", notification);
    if (notification.getId() != null) {
        throw new BadRequestAlertException("A new notification cannot already have an ID", ENTITY_NAME, ErrorConstants.ERR_ID_EXISTS);
    }
    Notification result = notificationService.saveNotification(notification);
    return ResponseEntity.created(new URI("/api/notifications/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) URI(java.net.URI) Notification(com.arnaugarcia.uplace.domain.Notification) 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