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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations