Esempio n. 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;
  }
Esempio n. 2
0
  public void updateUserLocationAndIncreaseDailySentCount(
      Long userId, DateTime photoDate, Location location, City city) {
    UserDetails userDetails = getUserDetails(userId);
    userDetails.setLastSentTime(photoDate);
    userDetails.setLastLocationTime(photoDate);
    userDetails.setLocation(location);
    userDetails.setCurrentCity(city);
    userDetails.setLastInteractionTime(photoDate);
    userDetails.setComeBackReminderTime(null);

    Long currentCount =
        statisticsService.incrementUserDailySentPhotoCount(userId, photoDate.toLocalDate());

    if (currentCount >= userDetails.getSendLimitPerDay()) {
      userDetails.setSendAllowedTime(photoDate.withTimeAtStartOfDay().plusDays(1));
    }

    userDetailsRepository.save(userDetails);
  }