예제 #1
0
  public UserProfileDto getUserProfile(Long userId) {
    UserDetails userDetails = getUserDetails(userId);

    UserProfileDto userProfileDto = new UserProfileDto();
    if (userDetails.getLastLocationTime() != null) {
      userProfileDto.setLastPlace(
          CityUtils.getLocationName(
              userDetails.getCurrentCity(), MAX_LOCATION_NAME_PROFILE_DETAILS));
      userProfileDto.setLastLat(userDetails.getLocation().getLatitude());
      userProfileDto.setLastLng(userDetails.getLocation().getLongitude());
      userProfileDto.setLastLocationTime(userDetails.getLastInteractionTime().toDate());
    }

    User user = userDetails.getUser();
    userProfileDto.setEmailRegistration(user.getEmailRegistration());
    userProfileDto.setNick(user.getNickname());

    Long userRank = rankingService.getRank(userId);
    if (userRank == null) {
      userProfileDto.setRank("No rank");
    } else {
      userProfileDto.setRank(userRank.toString());
      Long score = rankingService.getScore(userId);
      userProfileDto.setRankScore(score < 0 ? "< 0" : String.valueOf(score));
    }

    UserStatisticsDto userStatistics = statisticsService.getUserStatistics(userId);
    userProfileDto.setTotalDislikes(userStatistics.getTotalDislikeCount());
    userProfileDto.setTotalLikes(userStatistics.getTotalLikeCount());
    userProfileDto.setCitiesCount(userStatistics.getTotalCityCount());
    userProfileDto.setUnseenPhotoCount(userStatistics.getUnseenPhotoCount());
    userProfileDto.setDailySendLimitLeft(getSentLimitLeft(userDetails, userStatistics));
    userProfileDto.setNewActivities(userStatistics.getHasNewActivities());
    userProfileDto.setNewPhotoReplyActivities(userStatistics.getHasNewPhotoReplyActivities());
    userProfileDto.setUnreadInboxItemCount(userStatistics.getUnreadInboxItemCount());
    userProfileDto.setId(userId);

    DateTime now = DateTime.now();
    if (userDetails.getLastInteractionTime() != null
        && userDetails.getLastInteractionTime().isBefore(now.minusMinutes(10))) {
      userDetails.setLastInteractionTime(now);
      userDetails.setComeBackReminderTime(null);
      userDetailsRepository.save(userDetails);
    }

    return userProfileDto;
  }
예제 #2
0
 private Long getSentLimitLeft(UserDetails userDetails, UserStatisticsDto userStatistics) {
   return userDetails.getSendLimitPerDay() - userStatistics.getDailySendCount();
 }