コード例 #1
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);
  }
コード例 #2
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;
  }