Skip to content

Commit

Permalink
Merge pull request #231 from team-winey/refactor/#230
Browse files Browse the repository at this point in the history
  • Loading branch information
sss4920 authored Feb 22, 2024
2 parents e46cc3c + 32b916c commit 45ec08e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.winey.server.controller.response.user;

import org.winey.server.domain.user.UserLevel;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -25,14 +27,16 @@ public static class UserData {
private Long amountSavedHundredDays;
private Long amountSavedTwoWeeks;
private Long amountSpentTwoWeeks;
private Long remainingAmount;
private Long remainingCount;
}


public static UserResponseDto of(Long userId, String nickname, String userLevel,
Boolean fcmIsAllowed, Long accumulatedAmount, Long amountSavedHundredDays, Long amountSavedTwoWeeks,
Long amountSpentTwoWeeks) {
Long amountSpentTwoWeeks, Long remainingAmount, Long remainingCount) {
UserData userData = new UserData(userId, nickname, userLevel, fcmIsAllowed, accumulatedAmount,
amountSavedHundredDays, amountSavedTwoWeeks, amountSpentTwoWeeks);
amountSavedHundredDays, amountSavedTwoWeeks, amountSpentTwoWeeks,remainingAmount,remainingCount);
return new UserResponseDto(userData);
}
}
15 changes: 13 additions & 2 deletions src/main/java/org/winey/server/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,23 @@ public UserResponseDto getUser(Long userId) {
Long amountSavedTwoWeeks = feedRepository.getSavedAmountForPeriod(user, twoWeeksAgo);
Long amountSpentTwoWeeks = feedRepository.getSpentAmountForPeriod(user, twoWeeksAgo);

UserLevel nextUserLevel = UserLevel.getNextUserLevel(user.getUserLevel());

long savedAmountOfUser = user.getSavedAmount() == null ? 0L : user.getSavedAmount(); //๊ธฐ์กด์˜ getSavedAmount()ํ–ˆ์„ ์‹œ null -> 0L๋กœ ์ฒ˜๋ฆฌ
long savedCountOfUser = user.getSavedCount() == null ? 0L : user.getSavedCount(); //์œ„์™€ ์ด์œ  ๊ฐ™์Œ.

long remainingAmount = nextUserLevel == null ? 0L : nextUserLevel.getMinimumAmount() - savedAmountOfUser;
long remainingCount = nextUserLevel == null ? 0L : nextUserLevel.getMinimumCount() - savedCountOfUser;

return UserResponseDto.of(user.getUserId(), user.getNickname(),
user.getUserLevel().getName(), user.getFcmIsAllowed(),
user.getUserLevel().getName(),
user.getFcmIsAllowed(),
user.getSavedAmount() == null ? 0L : user.getSavedAmount(),
amountSavedHundredDays == null ? 0L : amountSavedHundredDays,
amountSavedTwoWeeks == null ? 0L : amountSavedTwoWeeks,
amountSpentTwoWeeks == null ? 0L : amountSpentTwoWeeks
amountSpentTwoWeeks == null ? 0L : amountSpentTwoWeeks,
remainingAmount < 0 ? 0L : remainingAmount,
remainingCount < 0 ? 0L : remainingCount
);
}

Expand Down

0 comments on commit 45ec08e

Please sign in to comment.