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; }
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); }
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); } }
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; }
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); }
public UserDetails saveUserDetails(UserDetails userDetails) { return userDetailsRepository.save(userDetails); }
public UserDetails getUserDetails(Long userId) { return userDetailsRepository.findOne(userId); }