From 885935bbb5b0bc108a63469d9b82aab43037c6ed Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 21:27:38 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[refactor]=20=ED=8F=89=EA=B7=A0=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20100=EB=8B=A8=EC=9C=84=EB=A1=9C=20=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EC=A7=80=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 4e52e77d..bc795c0d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -1,5 +1,7 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.service; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; @@ -103,22 +105,23 @@ public List getAllConsumptionGoalCategories(L Long avgConsumeAmount = avgDto.getAverageAmount(); Long myConsumeAmount = myConsumptionAmountDto.getMyAmount(); + Long roundedAvgConsumeAmount = roundToNearest100(avgConsumeAmount); + long consumeAmountDifference; - if (avgConsumeAmount == 0L) { + if (roundedAvgConsumeAmount == 0L) { consumeAmountDifference = -myConsumeAmount; } else { - consumeAmountDifference = myConsumeAmount - avgConsumeAmount; + consumeAmountDifference = myConsumeAmount - roundedAvgConsumeAmount; } return AllConsumptionCategoryResponseDto.builder() .categoryName(category.getName()) - .avgAmount(avgConsumeAmount) + .avgAmount(roundedAvgConsumeAmount) .amountDifference(consumeAmountDifference) .build(); }) .collect(Collectors.toList()); - } @Override @@ -199,17 +202,18 @@ public List getAllConsumptionCategories(Long Long avgConsumeAmount = avgDto.getAverageAmount(); Long myConsumeAmount = myConsumptionAmountDto.getMyAmount(); - long consumeAmountDifference; + Long roundedAvgConsumeAmount = roundToNearest100(avgConsumeAmount); - if (avgConsumeAmount == 0L) { + long consumeAmountDifference; + if (roundedAvgConsumeAmount == 0L) { consumeAmountDifference = -myConsumeAmount; } else { - consumeAmountDifference = myConsumeAmount - avgConsumeAmount; + consumeAmountDifference = myConsumeAmount - roundedAvgConsumeAmount; } return AllConsumptionCategoryResponseDto.builder() .categoryName(category.getName()) - .avgAmount(avgConsumeAmount) + .avgAmount(roundedAvgConsumeAmount) .amountDifference(consumeAmountDifference) .build(); }) @@ -347,6 +351,16 @@ private String getCategoryNameById(Long categoryId) { return category.getName(); } + private Long roundToNearest100(Long amount) { + if (amount == null) { + return 0L; + } + BigDecimal decimalAmount = BigDecimal.valueOf(amount); + BigDecimal roundedAmount = decimalAmount.divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + return roundedAmount.longValue(); + } + @Override @Transactional public ConsumptionGoalResponseListDto updateConsumptionGoals(Long userId, From 964353604d26645f6435e1d05decaa606ae89db8 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:16:34 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[refactor]=20=ED=8F=89=EA=B7=A0=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=2010=EB=8B=A8=EC=9C=84=EB=A1=9C=20=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EC=A7=80=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index bc795c0d..75299137 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -105,7 +105,7 @@ public List getAllConsumptionGoalCategories(L Long avgConsumeAmount = avgDto.getAverageAmount(); Long myConsumeAmount = myConsumptionAmountDto.getMyAmount(); - Long roundedAvgConsumeAmount = roundToNearest100(avgConsumeAmount); + Long roundedAvgConsumeAmount = roundToNearest10(avgConsumeAmount); long consumeAmountDifference; @@ -202,7 +202,7 @@ public List getAllConsumptionCategories(Long Long avgConsumeAmount = avgDto.getAverageAmount(); Long myConsumeAmount = myConsumptionAmountDto.getMyAmount(); - Long roundedAvgConsumeAmount = roundToNearest100(avgConsumeAmount); + Long roundedAvgConsumeAmount = roundToNearest10(avgConsumeAmount); long consumeAmountDifference; if (roundedAvgConsumeAmount == 0L) { @@ -351,13 +351,13 @@ private String getCategoryNameById(Long categoryId) { return category.getName(); } - private Long roundToNearest100(Long amount) { + private Long roundToNearest10(Long amount) { if (amount == null) { return 0L; } BigDecimal decimalAmount = BigDecimal.valueOf(amount); - BigDecimal roundedAmount = decimalAmount.divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP) - .multiply(BigDecimal.valueOf(100)); + BigDecimal roundedAmount = decimalAmount.divide(BigDecimal.valueOf(10), RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(10)); return roundedAmount.longValue(); } From 34d09ebc6d14356299e1fada5562a7f4b45686e8 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:25:58 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[refactor]=20=EC=86=8C=EB=B9=84=20=EA=B1=B4?= =?UTF-8?q?=EC=88=98=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=86=8C=EB=B9=84?= =?UTF-8?q?=20=EA=B8=88=EC=95=A1=EC=9D=B4=20=EC=A1=B4=EC=9E=AC=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20count?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 126 +++++++++--------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index ac2fe37c..2b7b0bfb 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -24,88 +24,92 @@ public interface ConsumptionGoalRepository extends JpaRepository findConsumptionGoalByUserIdAndGoalMonth(Long userId, LocalDate goalMonth); - Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User user, Category category, LocalDate goalMonth); + Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User user, Category category, + LocalDate goalMonth); @Query("SELECT AVG(cg.consumeAmount) FROM ConsumptionGoal cg " + - "JOIN cg.category c " + - "WHERE c.id = :categoryId " + - "AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek " + - "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + - "AND cg.user.gender = :peerGender") + "JOIN cg.category c " + + "WHERE c.id = :categoryId " + + "AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek " + + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + + "AND cg.user.gender = :peerGender") Optional findAvgConsumptionByCategoryIdAndCurrentWeek( - @Param("categoryId") Long categoryId, - @Param("startOfWeek") LocalDate startOfWeek, - @Param("endOfWeek") LocalDate endOfWeek, - @Param("peerAgeStart") int peerAgeStart, - @Param("peerAgeEnd") int peerAgeEnd, - @Param("peerGender") Gender peerGender); + @Param("categoryId") Long categoryId, + @Param("startOfWeek") LocalDate startOfWeek, + @Param("endOfWeek") LocalDate endOfWeek, + @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, + @Param("peerGender") Gender peerGender); @Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.AvgConsumptionGoalDto(" + - "cg.category.id, AVG(cg.consumeAmount))" + - "FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + - "AND cg.user.gender = :peerGender " + - "AND cg.goalMonth >= :currentMonth " + - "GROUP BY cg.category.id " + - "ORDER BY AVG(cg.consumeAmount) DESC") + "cg.category.id, AVG(cg.consumeAmount))" + + "FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + + "AND cg.user.gender = :peerGender " + + "AND cg.goalMonth >= :currentMonth " + + "GROUP BY cg.category.id " + + "ORDER BY AVG(cg.consumeAmount) DESC") List findAvgConsumptionAmountByCategory( - @Param("peerAgeStart") int peerAgeStart, - @Param("peerAgeEnd") int peerAgeEnd, - @Param("peerGender") Gender peerGender, - @Param("currentMonth") LocalDate currentMonth); + @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, + @Param("peerGender") Gender peerGender, + @Param("currentMonth") LocalDate currentMonth); @Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.MyConsumptionGoalDto(" + - "cg.category.id, SUM(cg.consumeAmount)) " + - "FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "AND cg.user.id = :userId " + - "GROUP BY cg.category.id " + - "ORDER BY cg.category.id") + "cg.category.id, SUM(cg.consumeAmount)) " + + "FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.id = :userId " + + "GROUP BY cg.category.id " + + "ORDER BY cg.category.id") List findAllConsumptionAmountByUserId(@Param("userId") Long userId); @Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.AvgConsumptionGoalDto(" + - "cg.category.id, AVG(cg.goalAmount))" + - "FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + - "AND cg.user.gender = :peerGender " + - "AND cg.goalMonth >= :currentMonth " + - "GROUP BY cg.category.id " + - "ORDER BY AVG(cg.goalAmount) DESC") + "cg.category.id, AVG(cg.goalAmount))" + + "FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + + "AND cg.user.gender = :peerGender " + + "AND cg.goalMonth >= :currentMonth " + + "GROUP BY cg.category.id " + + "ORDER BY AVG(cg.goalAmount) DESC") List findAvgGoalAmountByCategory( - @Param("peerAgeStart") int peerAgeStart, - @Param("peerAgeEnd") int peerAgeEnd, - @Param("peerGender") Gender peerGender, - @Param("currentMonth") LocalDate currentMonth); + @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, + @Param("peerGender") Gender peerGender, + @Param("currentMonth") LocalDate currentMonth); @Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.MyConsumptionGoalDto(" + - "cg.category.id, SUM(cg.goalAmount)) " + - "FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "AND cg.user.id = :userId " + - "GROUP BY cg.category.id " + - "ORDER BY cg.category.id") + "cg.category.id, SUM(cg.goalAmount)) " + + "FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.id = :userId " + + "GROUP BY cg.category.id " + + "ORDER BY cg.category.id") List findAllGoalAmountByUserId(@Param("userId") Long userId); @Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.CategoryConsumptionCountDto(" + - "cg.category.id, COUNT(cg)) " + - "FROM ConsumptionGoal cg " + - "WHERE cg.category.isDefault = true " + - "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + - "AND cg.user.gender = :peerGender " + - "AND cg.goalMonth >= :currentMonth " + - "GROUP BY cg.category.id " + - "ORDER BY COUNT(cg) DESC") + "cg.category.id, COUNT(cg)) " + + "FROM ConsumptionGoal cg " + + "WHERE cg.category.isDefault = true " + + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + + "AND cg.user.gender = :peerGender " + + "AND cg.goalMonth >= :currentMonth " + + "AND cg.consumeAmount > 0 " + + "GROUP BY cg.category.id " + + "ORDER BY COUNT(cg) DESC") List findTopCategoriesByConsumptionCount( - @Param("peerAgeStart") int peerAgeStart, - @Param("peerAgeEnd") int peerAgeEnd, - @Param("peerGender") Gender peerGender, - @Param("currentMonth") LocalDate currentMonth); + @Param("peerAgeStart") int peerAgeStart, + @Param("peerAgeEnd") int peerAgeEnd, + @Param("peerGender") Gender peerGender, + @Param("currentMonth") LocalDate currentMonth); @Modifying @Query("UPDATE ConsumptionGoal cg SET cg.deleted = TRUE WHERE cg.category.id = :categoryId AND cg.user.id = :userId") void softDeleteByCategoryIdAndUserId(@Param("categoryId") Long categoryId, @Param("userId") Long userId); @Query("SELECT cg FROM ConsumptionGoal cg WHERE cg.category.id = :categoryId AND cg.user.id = :userId AND cg.deleted = FALSE") - Optional findByCategoryIdAndUserId(@Param("categoryId") Long categoryId, @Param("userId") Long userId);} + Optional findByCategoryIdAndUserId(@Param("categoryId") Long categoryId, + @Param("userId") Long userId); +} From 120b459765972a95f5fc51bab6a89fe17f732452 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:31:14 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[refactor]=20consumptionGoal=20deleted=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20false=20=ED=95=84=ED=84=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index 2b7b0bfb..d9f794be 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -30,6 +30,7 @@ Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User @Query("SELECT AVG(cg.consumeAmount) FROM ConsumptionGoal cg " + "JOIN cg.category c " + "WHERE c.id = :categoryId " + + "AND cg.deleted = false " + "AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek " + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + "AND cg.user.gender = :peerGender") @@ -45,6 +46,7 @@ Optional findAvgConsumptionByCategoryIdAndCurrentWeek( "cg.category.id, AVG(cg.consumeAmount))" + "FROM ConsumptionGoal cg " + "WHERE cg.category.isDefault = true " + + "AND cg.deleted = false " + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + "AND cg.user.gender = :peerGender " + "AND cg.goalMonth >= :currentMonth " + @@ -60,6 +62,7 @@ List findAvgConsumptionAmountByCategory( "cg.category.id, SUM(cg.consumeAmount)) " + "FROM ConsumptionGoal cg " + "WHERE cg.category.isDefault = true " + + "AND cg.deleted = false " + "AND cg.user.id = :userId " + "GROUP BY cg.category.id " + "ORDER BY cg.category.id") @@ -69,6 +72,7 @@ List findAvgConsumptionAmountByCategory( "cg.category.id, AVG(cg.goalAmount))" + "FROM ConsumptionGoal cg " + "WHERE cg.category.isDefault = true " + + "AND cg.deleted = false " + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + "AND cg.user.gender = :peerGender " + "AND cg.goalMonth >= :currentMonth " + @@ -84,6 +88,7 @@ List findAvgGoalAmountByCategory( "cg.category.id, SUM(cg.goalAmount)) " + "FROM ConsumptionGoal cg " + "WHERE cg.category.isDefault = true " + + "AND cg.deleted = false " + "AND cg.user.id = :userId " + "GROUP BY cg.category.id " + "ORDER BY cg.category.id") @@ -93,6 +98,7 @@ List findAvgGoalAmountByCategory( "cg.category.id, COUNT(cg)) " + "FROM ConsumptionGoal cg " + "WHERE cg.category.isDefault = true " + + "AND cg.deleted = false " + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + "AND cg.user.gender = :peerGender " + "AND cg.goalMonth >= :currentMonth " + From 6d17668ff13578356ccd93120c3eeb3f9171c5d4 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:41:39 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[refactor]=20=EB=A9=94=EC=9D=B8=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC=20=EC=86=8C?= =?UTF-8?q?=EB=B9=84=20=EA=B8=88=EC=95=A1=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java index 75299137..51183197 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceImpl.java @@ -4,6 +4,8 @@ import java.math.RoundingMode; import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.Comparator; @@ -145,11 +147,17 @@ public ConsumptionAnalysisResponseDto getTopCategoryAndConsumptionAmount(Long us Long topConsumptionGoalCategoryId = avgConsumptionGoalList.get(0).getCategoryId(); + LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay(); + LocalDateTime endOfWeekDateTime = endOfWeek.atTime(LocalTime.MAX); + Long currentWeekConsumptionAmount = consumptionGoalRepository - .findAvgConsumptionByCategoryIdAndCurrentWeek(topConsumptionGoalCategoryId, startOfWeek, endOfWeek, + .findAvgConsumptionByCategoryIdAndCurrentWeek(topConsumptionGoalCategoryId, startOfWeekDateTime, + endOfWeekDateTime, peerAgeStart, peerAgeEnd, peerGender) .orElse(0L); + currentWeekConsumptionAmount = roundToNearest10(currentWeekConsumptionAmount); + String topGoalCategory = getCategoryNameById(topConsumptionGoalCategoryId); return consumptionGoalConverter.toTopCategoryAndConsumptionAmount(topGoalCategory, From 1ac5e3b08cdc9702341c354347929cc9eb08dcf9 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:42:08 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[refactor]=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC?= =?UTF-8?q?=20=EC=86=8C=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20LocalDate=20->=20LocalDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ConsumptionGoalRepository.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java index d9f794be..46ae852e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/consumptiongoal/repository/ConsumptionGoalRepository.java @@ -1,6 +1,7 @@ package com.bbteam.budgetbuddies.domain.consumptiongoal.repository; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -31,13 +32,13 @@ Optional findConsumptionGoalByUserAndCategoryAndGoalMonth(User "JOIN cg.category c " + "WHERE c.id = :categoryId " + "AND cg.deleted = false " + - "AND cg.goalMonth BETWEEN :startOfWeek AND :endOfWeek " + + "AND cg.createdAt BETWEEN :startOfWeek AND :endOfWeek " + "AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " + "AND cg.user.gender = :peerGender") Optional findAvgConsumptionByCategoryIdAndCurrentWeek( @Param("categoryId") Long categoryId, - @Param("startOfWeek") LocalDate startOfWeek, - @Param("endOfWeek") LocalDate endOfWeek, + @Param("startOfWeek") LocalDateTime startOfWeek, + @Param("endOfWeek") LocalDateTime endOfWeek, @Param("peerAgeStart") int peerAgeStart, @Param("peerAgeEnd") int peerAgeEnd, @Param("peerGender") Gender peerGender); From 2003df7a63eeebc3b2911be1f5e85942190a39e8 Mon Sep 17 00:00:00 2001 From: MJJ Date: Thu, 22 Aug 2024 22:43:32 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[refactor]=20=EC=9D=B4=EB=B2=88=20=EC=A3=BC?= =?UTF-8?q?=20=EC=86=8C=EB=B9=84=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ConsumptionGoalServiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java index e7ede59f..07b42d1c 100644 --- a/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java +++ b/src/test/java/com/bbteam/budgetbuddies/domain/consumptiongoal/service/ConsumptionGoalServiceTest.java @@ -6,6 +6,8 @@ import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.temporal.TemporalAdjusters; import java.util.List; import java.util.NoSuchElementException; @@ -308,6 +310,9 @@ void getTopCategoryAndConsumptionAmount_Success() { LocalDate startOfWeek = goalMonthRandomDay.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); LocalDate endOfWeek = goalMonthRandomDay.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); + LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay(); + LocalDateTime endOfWeekDateTime = endOfWeek.atTime(LocalTime.MAX); + ConsumptionGoal topConsumptionGoal = ConsumptionGoal.builder() .goalAmount(5000L) .consumeAmount(3000L) @@ -338,7 +343,7 @@ void getTopCategoryAndConsumptionAmount_Success() { .willReturn(avgConsumptionGoalList); given(consumptionGoalRepository.findAvgConsumptionByCategoryIdAndCurrentWeek( - defaultCategory.getId(), startOfWeek, endOfWeek, + defaultCategory.getId(), startOfWeekDateTime, endOfWeekDateTime, peerAgeStart, peerAgeEnd, peerGender)) .willReturn(Optional.of(currentWeekConsumptionGoal.getConsumeAmount()));