@RequestMapping(value = "/update/read/{phoneNumber}/{code}", method = RequestMethod.POST) public ResponseEntity<ResponseWrapper> updateReadStatus( @PathVariable("phoneNumber") String phoneNumber, @PathVariable("code") String code, @RequestParam("uid") String uid) throws Exception { User user = userManagementService.findByInputNumber(phoneNumber); Notification notification = notificationService.loadNotification(uid); log.info( "updating notification read status for user uid : {}, notification uid : {}", user.getUid(), uid); if (!notification.getTarget().equals(user)) { return RestUtil.accessDeniedResponse(); } if (notification.isRead() && notification.isViewedOnAndroid()) { log.info("Trying to update notification when already read"); return RestUtil.errorResponse(HttpStatus.ALREADY_REPORTED, RestMessage.ALREADY_UPDATED); } else { notificationService.updateNotificationsViewedAndRead(Collections.singleton(uid)); return RestUtil.messageOkayResponse(RestMessage.NOTIFICATION_UPDATED); } }
@RequestMapping(value = "/update/read/batch/{phoneNumber}/{code}", method = RequestMethod.POST) public ResponseEntity<ResponseWrapper> updateViewedStatusBatch( @PathVariable String phoneNumber, @PathVariable String code, @RequestParam boolean read, @RequestParam List<String> notificationUids) { try { if (notificationUids != null && !notificationUids.isEmpty()) { notificationService.updateNotificationsViewedAndRead(new HashSet<>(notificationUids)); return RestUtil.messageOkayResponse(RestMessage.NOTIFICATION_UPDATED); } else { return RestUtil.messageOkayResponse(RestMessage.EMPTY_LIST); } } catch (Exception e) { return RestUtil.errorResponse(HttpStatus.BAD_REQUEST, RestMessage.ERROR); } }