use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class RealEstateResource method createRealEstate.
/**
* POST /real-estates : Create a new realEstate.
*
* @param realEstate the realEstate to create
* @return the ResponseEntity with status 201 (Created) and with body the new realEstate, or with status 400 (Bad Request) if the realEstate has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/real-estates")
@Timed
public ResponseEntity<RealEstate> createRealEstate(@Valid @RequestBody RealEstate realEstate) throws URISyntaxException {
log.debug("REST request to save RealEstate : {}", realEstate);
if (realEstate.getId() != null) {
throw new BadRequestAlertException("A new realEstate cannot already have an ID", ENTITY_NAME, "idexists");
}
RealEstate result = realEstateService.save(realEstate);
return ResponseEntity.created(new URI("/api/real-estates/" + 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 NotificationService method updates.
@Transactional()
public List<Notification> updates(List<Notification> notifications) {
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
// if there are a notification that does not belongs to the user and isn't admin... error
notifications.forEach(notification -> {
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);
}
});
return notificationRepository.save(notifications);
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class NotificationService method markAs.
@Transactional(readOnly = true)
public List<Notification> markAs(List<Notification> notifications, Boolean status) {
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
notifications.forEach(notification -> {
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);
} else {
notification.setRead(status);
}
});
return notificationRepository.save(notifications);
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class NotificationService method findOneByType.
/**
* Get one notification by id.
*
* @param id the id of the entity
* @return the entity
*/
@Transactional(readOnly = true)
public Notification findOneByType(NotificationType notificationType, Long id) {
log.debug("Request to get Notification : {}", id);
Notification notification = null;
switch(notificationType) {
case NOTIFICATION:
notification = notificationRepository.findOneByType(NotificationType.NOTIFICATION, id);
break;
case REQUEST:
notification = notificationRepository.findOneByType(NotificationType.REQUEST, id);
break;
case ALERT:
throw new BadRequestAlertException("Not yet implemented", ENTITY_REQUEST, ErrorConstants.NOT_IMPLEMENTED);
}
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
if (notification == null || !notification.getType().equals(NotificationType.NOTIFICATION)) {
throw new BadRequestAlertException("No notification was found with this ID", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_ID);
}
// 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);
}
return notification;
}
use of com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException in project uplace.es by Uplace.
the class NotificationService method deletes.
public void deletes(List<Notification> notificationList) {
log.debug("Request to delete a list of Notification : {}", notificationList.size());
// TODO: Check if the notification exists and is a notification
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
// Checks if the user is the correct user
notificationList.forEach(notification -> {
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(notificationList);
}
Aggregations