示例#1
0
  public User createUser(
      String username, String email, String password, String nickname, boolean emailRegistration) {
    User user = new User();
    user.setUsername(username);
    user.setEmail(email);
    user.setPassword(encodePassword(password));
    user.setNickname(nickname);
    user.setEmailRegistration(emailRegistration);

    String verificationCode = UUID.randomUUID().toString();
    user.setVerificationCode(verificationCode);

    user = userRepository.save(user);

    UserDetails userDetails = new UserDetails();
    userDetails.setUserId(user.getId());
    userDetails.setSendLimitPerDay(DEFAULT_SEND_LIMIT_PER_DAY);
    userDetails.setReceiveLimitPerDay(DEFAULT_RECEIVE_LIMIT_PER_DAY);
    userDetailsRepository.save(userDetails);

    UserStatistics userStatistics = new UserStatistics();
    userStatistics.setUserId(user.getId());
    userStatisticsRepository.save(userStatistics);

    return user;
  }
示例#2
0
  public void updateSettings(UserSettingsDto userSettings, Long userId) {
    UserDetails userDetails = getUserDetails(userId);
    if (userSettings.getReceiveLimitPerDay() != null) {
      userDetails.setReceiveLimitPerDay(userSettings.getReceiveLimitPerDay());
    }
    userDetails.setReceiveNewPhotoNotifications(userSettings.getReceiveNewPhotoNotifications());
    userDetails.setReceiveCommentNotifications(userSettings.getReceiveCommentNotifications());

    if (StringUtils.hasText(userSettings.getNickname())) {
      userDetails.getUser().setNickname(userSettings.getNickname().trim());
      userRepository.save(userDetails.getUser());
    }

    userDetailsRepository.save(userDetails);
  }
示例#3
0
  public void updateLocation(Long userId, BigDecimal longitude, BigDecimal latitude) {
    UserDetails userDetails = getUserDetails(userId);
    Location currentLocation = userDetails.getLocation();
    if (currentLocation == null
        || longitude.compareTo(currentLocation.getLongitude()) != 0
        || latitude.compareTo(currentLocation.getLatitude()) != 0) {
      userDetails.setLastLocationTime(DateTime.now());
      userDetails.setLocation(new Location(latitude, longitude));
      userDetails.setCurrentCity(cityService.findNearest(latitude, longitude));
      userDetails.setLastInteractionTime(DateTime.now());
      userDetails.setComeBackReminderTime(null);

      userDetailsRepository.save(userDetails);
    }
  }
示例#4
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;
  }
示例#5
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);
  }
示例#6
0
 public UserDetails saveUserDetails(UserDetails userDetails) {
   return userDetailsRepository.save(userDetails);
 }