コード例 #1
0
  @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);
    }
  }
コード例 #2
0
  @RequestMapping(value = "/list/since/{phoneNumber}/{code}", method = RequestMethod.GET)
  public ResponseEntity<ResponseWrapper> getNotificationsSince(
      @PathVariable String phoneNumber,
      @PathVariable String code,
      @RequestParam(value = "createdSince", required = false) Long createdSince) {

    User user = userManagementService.findByInputNumber(phoneNumber);
    Instant intervalStart = createdSince == null ? null : Instant.ofEpochMilli(createdSince);
    List<Notification> notifications =
        notificationService.fetchAndroidNotificationsSince(user.getUid(), intervalStart);
    List<NotificationDTO> notificationDTOs =
        notifications
            .stream()
            .filter(NotificationDTO::isNotificationOfTypeForDTO)
            .map(NotificationDTO::convertToDto)
            .collect(Collectors.toList());
    NotificationWrapper wrapper = new NotificationWrapper(notificationDTOs);
    return RestUtil.okayResponseWithData(RestMessage.NOTIFICATIONS, wrapper);
  }
コード例 #3
0
  @RequestMapping(value = "/list/{phoneNumber}/{code}", method = RequestMethod.GET)
  public ResponseEntity<ResponseWrapper> getNotifications(
      @PathVariable("phoneNumber") String phoneNumber,
      @PathVariable("code") String code,
      @RequestParam(value = "page", required = false) Integer queryPage,
      @RequestParam(value = "size", required = false) Integer queryPageSize) {

    User user = userManagementService.findByInputNumber(phoneNumber);
    final int pageNumber = (queryPage == null) ? 0 : queryPage;
    final int pageSize = (queryPageSize == null) ? pageLength : queryPageSize;

    Page<Notification> pageable =
        notificationService.fetchPagedAndroidNotifications(user, pageNumber, pageSize);
    log.info(
        "pageable size = {}, from page number = {}, with page size = {}",
        pageable.getContent().size(),
        pageNumber,
        pageSize);

    ResponseEntity<ResponseWrapper> responseWrapper;

    if (pageNumber > pageable.getTotalPages()) {
      responseWrapper =
          RestUtil.errorResponse(HttpStatus.BAD_REQUEST, RestMessage.NOTIFICATIONS_FINISHED);
    } else {
      List<NotificationDTO> notificationDTOList =
          pageable
              .getContent()
              .stream()
              .filter(NotificationDTO::isNotificationOfTypeForDTO)
              .map(NotificationDTO::convertToDto)
              .collect(Collectors.toList());
      log.info("number of DTOs created : {}", notificationDTOList.size());
      NotificationWrapper notificationWrapper =
          new NotificationWrapper(pageable, notificationDTOList);
      responseWrapper =
          RestUtil.okayResponseWithData(RestMessage.NOTIFICATIONS, notificationWrapper);
    }

    return responseWrapper;
  }