Skip to content

Commit

Permalink
Merge pull request #57 from BudgetBuddiesTeam/refactor/#49
Browse files Browse the repository at this point in the history
[refactor] ConsumptionGoalServiceImpl checkPeerInfo 수정
  • Loading branch information
m3k0813 authored Jul 30, 2024
2 parents 0eef413 + e42cc8e commit 635ebb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class ConsumptionGoalServiceImpl implements ConsumptionGoalService {
public List<TopGoalCategoryResponseDTO> getTopGoalCategories(int top, Long userId, int peerAgeS, int peerAgeE,
String peerG) {

User user = findUserById(userId);

checkPeerInfo(user, peerAgeS, peerAgeE, peerG);
checkPeerInfo(userId, peerAgeS, peerAgeE, peerG);

List<ConsumptionGoal> topGoals = consumptionGoalRepository.findTopCategoriesAndGoalAmount(top, peerAgeStart,
peerAgeEnd, peerGender);
Expand All @@ -66,9 +64,7 @@ public List<TopGoalCategoryResponseDTO> getTopGoalCategories(int top, Long userI
@Transactional(readOnly = true)
public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) {

User user = findUserById(userId);

checkPeerInfo(user, peerAgeS, peerAgeE, peerG);
checkPeerInfo(userId, peerAgeS, peerAgeE, peerG);

return PeerInfoConverter.fromEntity(peerAgeStart, peerAgeEnd, peerGender);
}
Expand All @@ -77,9 +73,7 @@ public PeerInfoResponseDTO getPeerInfo(Long userId, int peerAgeS, int peerAgeE,
@Transactional(readOnly = true)
public ConsumptionAnalysisResponseDTO getTopCategoryAndConsumptionAmount(Long userId) {

User user = findUserById(userId);

checkPeerInfo(user, 0, 0, "none");
checkPeerInfo(userId, 0, 0, "none");

ConsumptionGoal topConsumptionGoal = consumptionGoalRepository.findTopCategoriesAndGoalAmount(1, peerAgeStart,
peerAgeEnd, peerGender).get(0);
Expand Down Expand Up @@ -107,7 +101,9 @@ private User findUserById(Long userId) {
return user.get();
}

private void checkPeerInfo(User user, int peerAgeS, int peerAgeE, String peerG) {
private void checkPeerInfo(Long userId, int peerAgeS, int peerAgeE, String peerG) {

User user = findUserById(userId);

Gender gender = Gender.valueOf(peerG.toUpperCase());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ void getTopCategoryAndConsumptionAmount_Success() {
Category defaultCategory = Mockito.spy(Category.builder().name("디폴트 카테고리").user(null).isDefault(true).build());
given(defaultCategory.getId()).willReturn(-1L);

LocalDate goalMonthRandomDay = LocalDate.now();

ConsumptionGoal topConsumptionGoal = ConsumptionGoal.builder()
.goalAmount(5000L)
.consumeAmount(3000L)
.user(user)
.category(defaultCategory)
.goalMonth(goalMonthRandomDay)
.goalMonth(goalMonthRandomDay.minusWeeks(1))
.build();

ConsumptionGoal currentWeekConsumptionGoal = ConsumptionGoal.builder()
Expand Down

0 comments on commit 635ebb5

Please sign in to comment.