From 907e8a58391e5c493d31f125a8e591b06c707754 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Thu, 30 May 2024 18:20:26 +0900 Subject: [PATCH 01/13] =?UTF-8?q?fix:=20=EB=B0=B0=ED=8F=AC=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=B4=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EB=B9=8C=EB=93=9C=20=EB=B2=84=EC=A0=84=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 --- .github/workflows/deploy-batch.yml | 3 ++- .github/workflows/deploy-external-api.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-batch.yml b/.github/workflows/deploy-batch.yml index 248d1d513..77022c5c4 100644 --- a/.github/workflows/deploy-batch.yml +++ b/.github/workflows/deploy-batch.yml @@ -63,7 +63,8 @@ jobs: - name: docker build and push run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t pennyway/pennyway-batch ./pennyway-batch + docker build -t pennyway/pennyway-batch:${{ steps.get_version.outputs.VERSION }} ./pennyway-batch + docker build -t pennyway/pennyway-batch:latest ./pennyway-batch docker push pennyway/pennyway-batch:${{ steps.get_version.outputs.VERSION }} docker push pennyway/pennyway-batch:latest diff --git a/.github/workflows/deploy-external-api.yml b/.github/workflows/deploy-external-api.yml index 6da428a24..90182c77a 100644 --- a/.github/workflows/deploy-external-api.yml +++ b/.github/workflows/deploy-external-api.yml @@ -71,7 +71,8 @@ jobs: - name: docker build and push run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t pennyway/pennyway-was ./pennyway-app-external-api + docker build -t pennyway/pennyway-was:${{ steps.get_version.outputs.VERSION }} ./pennyway-app-external-api + docker build -t pennyway/pennyway-was:latest ./pennyway-app-external-api docker push pennyway/pennyway-was:${{ steps.get_version.outputs.VERSION }} docker push pennyway/pennyway-was:latest From 32ee78550e3eb0cc41df6fa6d66b3a1d9e3289c7 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:07:01 +0900 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20create=5Ftarget=5Famount()=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/ledger/service/TargetAmountSaveService.java | 10 ++++++++-- .../api/apis/ledger/usecase/TargetAmountUseCase.java | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java index 5f0a1c33f..b2fb60d1c 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java @@ -6,6 +6,9 @@ import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; import kr.co.pennyway.domain.domains.target.service.TargetAmountService; import kr.co.pennyway.domain.domains.user.domain.User; +import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; +import kr.co.pennyway.domain.domains.user.exception.UserErrorException; +import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -16,10 +19,13 @@ @Service @RequiredArgsConstructor public class TargetAmountSaveService { + private final UserService userService; private final TargetAmountService targetAmountService; - @DistributedLock(key = "#key.concat(#user.getId()).concat('_').concat(#date.getYear()).concat('-').concat(#date.getMonthValue())") - public TargetAmount createTargetAmount(String key, User user, LocalDate date) { + @DistributedLock(key = "#key.concat(#userId).concat('_').concat(#date.getYear()).concat('-').concat(#date.getMonthValue())") + public TargetAmount createTargetAmount(String key, Long userId, LocalDate date) { + User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); + if (targetAmountService.isExistsTargetAmountThatMonth(user.getId(), date)) { log.info("{}에 대한 날짜의 목표 금액이 이미 존재합니다.", date); throw new TargetAmountErrorException(TargetAmountErrorCode.ALREADY_EXIST_TARGET_AMOUNT); diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index 803b5801a..b467d92be 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -37,9 +37,7 @@ public class TargetAmountUseCase { @Transactional public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year, int month) { - User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); - - TargetAmount targetAmount = targetAmountSaveService.createTargetAmount(DistributedLockPrefix.TARGET_AMOUNT_USER, user, LocalDate.of(year, month, 1)); + TargetAmount targetAmount = targetAmountSaveService.createTargetAmount(DistributedLockPrefix.TARGET_AMOUNT_USER, userId, LocalDate.of(year, month, 1)); return TargetAmountDto.TargetAmountInfo.from(targetAmount); } From 85658715a3feec51eec439337738ccff7c98bc23 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:09:11 +0900 Subject: [PATCH 03/13] rename: recent_target_amount_search_service -> target_amount_search_service --- ...untSearchService.java => TargetAmountSearchService.java} | 2 +- .../api/apis/ledger/usecase/TargetAmountUseCase.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/{RecentTargetAmountSearchService.java => TargetAmountSearchService.java} (93%) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/RecentTargetAmountSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java similarity index 93% rename from pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/RecentTargetAmountSearchService.java rename to pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java index 50174528a..c68178955 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/RecentTargetAmountSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java @@ -8,7 +8,7 @@ @Service @RequiredArgsConstructor -public class RecentTargetAmountSearchService { +public class TargetAmountSearchService { private final TargetAmountService targetAmountService; @Transactional(readOnly = true) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index b467d92be..8c54f9135 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -2,8 +2,8 @@ import kr.co.pennyway.api.apis.ledger.dto.TargetAmountDto; import kr.co.pennyway.api.apis.ledger.mapper.TargetAmountMapper; -import kr.co.pennyway.api.apis.ledger.service.RecentTargetAmountSearchService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountSaveService; +import kr.co.pennyway.api.apis.ledger.service.TargetAmountSearchService; import kr.co.pennyway.common.annotation.UseCase; import kr.co.pennyway.domain.common.redisson.DistributedLockPrefix; import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; @@ -33,7 +33,7 @@ public class TargetAmountUseCase { private final SpendingService spendingService; private final TargetAmountSaveService targetAmountSaveService; - private final RecentTargetAmountSearchService recentTargetAmountSearchService; + private final TargetAmountSearchService targetAmountSearchService; @Transactional public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year, int month) { @@ -62,7 +62,7 @@ public List getTargetAmountsAndTotalSpendi @Transactional(readOnly = true) public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) { - return TargetAmountMapper.toRecentTargetAmountResponse(recentTargetAmountSearchService.readRecentTargetAmount(userId)); + return TargetAmountMapper.toRecentTargetAmountResponse(targetAmountSearchService.readRecentTargetAmount(userId)); } @Transactional From 48a4522b97072d94e977b4791bff3d2c55992cf6 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:18:54 +0900 Subject: [PATCH 04/13] refactor: get_target_amount_and_total_spending() --- .../service/TargetAmountSearchService.java | 18 ++++++++++++++++++ .../ledger/usecase/TargetAmountUseCase.java | 6 +----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java index c68178955..02e2b2ec3 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java @@ -1,16 +1,34 @@ package kr.co.pennyway.api.apis.ledger.service; +import kr.co.pennyway.api.apis.ledger.dto.TargetAmountDto; +import kr.co.pennyway.api.apis.ledger.mapper.TargetAmountMapper; +import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; +import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.target.domain.TargetAmount; +import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; +import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; import kr.co.pennyway.domain.domains.target.service.TargetAmountService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.util.Optional; + @Service @RequiredArgsConstructor public class TargetAmountSearchService { + private final SpendingService spendingService; private final TargetAmountService targetAmountService; + @Transactional(readOnly = true) + public TargetAmountDto.WithTotalSpendingRes readTargetAmountAndTotalSpending(Long userId, LocalDate date) { + TargetAmount targetAmount = targetAmountService.readTargetAmountThatMonth(userId, date).orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); + Optional totalSpending = spendingService.readTotalSpendingAmountByUserId(userId, date); + + return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); + } + @Transactional(readOnly = true) public Integer readRecentTargetAmount(Long userId) { return targetAmountService.readRecentTargetAmount(userId) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index 8c54f9135..97b25de06 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -22,7 +22,6 @@ import java.time.LocalDate; import java.util.List; -import java.util.Optional; @Slf4j @UseCase @@ -44,10 +43,7 @@ public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year @Transactional(readOnly = true) public TargetAmountDto.WithTotalSpendingRes getTargetAmountAndTotalSpending(Long userId, LocalDate date) { - TargetAmount targetAmount = targetAmountService.readTargetAmountThatMonth(userId, date).orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); - Optional totalSpending = spendingService.readTotalSpendingAmountByUserId(userId, date); - - return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); + return targetAmountSearchService.readTargetAmountAndTotalSpending(userId, date); } @Transactional(readOnly = true) From 5684d8206899e1993b9e9f138f8665011381154d Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:20:12 +0900 Subject: [PATCH 05/13] refactor: get_target_amounts_and_total_spendings() --- .../service/TargetAmountSearchService.java | 16 ++++++++++++++++ .../apis/ledger/usecase/TargetAmountUseCase.java | 11 +---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java index 02e2b2ec3..8882d1230 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java @@ -8,16 +8,22 @@ import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; import kr.co.pennyway.domain.domains.target.service.TargetAmountService; +import kr.co.pennyway.domain.domains.user.domain.User; +import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; +import kr.co.pennyway.domain.domains.user.exception.UserErrorException; +import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.List; import java.util.Optional; @Service @RequiredArgsConstructor public class TargetAmountSearchService { + private final UserService userService; private final SpendingService spendingService; private final TargetAmountService targetAmountService; @@ -29,6 +35,16 @@ public TargetAmountDto.WithTotalSpendingRes readTargetAmountAndTotalSpending(Lon return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); } + @Transactional(readOnly = true) + public List readTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { + User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); + + List targetAmounts = targetAmountService.readTargetAmountsByUserId(userId); + List totalSpendings = spendingService.readTotalSpendingsAmountByUserId(userId); + + return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, user.getCreatedAt().toLocalDate(), date); + } + @Transactional(readOnly = true) public Integer readRecentTargetAmount(Long userId) { return targetAmountService.readRecentTargetAmount(userId) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index 97b25de06..35d6a72bc 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -6,15 +6,11 @@ import kr.co.pennyway.api.apis.ledger.service.TargetAmountSearchService; import kr.co.pennyway.common.annotation.UseCase; import kr.co.pennyway.domain.common.redisson.DistributedLockPrefix; -import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.target.domain.TargetAmount; import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; import kr.co.pennyway.domain.domains.target.service.TargetAmountService; -import kr.co.pennyway.domain.domains.user.domain.User; -import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; -import kr.co.pennyway.domain.domains.user.exception.UserErrorException; import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -48,12 +44,7 @@ public TargetAmountDto.WithTotalSpendingRes getTargetAmountAndTotalSpending(Long @Transactional(readOnly = true) public List getTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { - User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); - - List targetAmounts = targetAmountService.readTargetAmountsByUserId(userId); - List totalSpendings = spendingService.readTotalSpendingsAmountByUserId(userId); - - return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, user.getCreatedAt().toLocalDate(), date); + return targetAmountSearchService.readTargetAmountsAndTotalSpendings(userId, date); } @Transactional(readOnly = true) From 62caa0468d527ce9a1a624ff8bf69ec39b96b253 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:21:57 +0900 Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20update=5Ftarget=5Famount=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger/service/TargetAmountSaveService.java | 15 +++++++++++++++ .../apis/ledger/usecase/TargetAmountUseCase.java | 11 ++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java index b2fb60d1c..abaaf64f3 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSaveService.java @@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; @@ -33,4 +34,18 @@ public TargetAmount createTargetAmount(String key, Long userId, LocalDate date) return targetAmountService.createTargetAmount(TargetAmount.of(-1, user)); } + + @Transactional + public TargetAmount updateTargetAmount(Long targetAmountId, Integer amount) { + TargetAmount targetAmount = targetAmountService.readTargetAmount(targetAmountId) + .orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); + + if (!targetAmount.isThatMonth()) { + throw new TargetAmountErrorException(TargetAmountErrorCode.INVALID_TARGET_AMOUNT_DATE); + } + + targetAmount.updateAmount(amount); + + return targetAmount; + } } diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index 35d6a72bc..a33de07fe 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -54,15 +54,8 @@ public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) @Transactional public TargetAmountDto.TargetAmountInfo updateTargetAmount(Long targetAmountId, Integer amount) { - TargetAmount targetAmount = targetAmountService.readTargetAmount(targetAmountId) - .orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); - - if (!targetAmount.isThatMonth()) { - throw new TargetAmountErrorException(TargetAmountErrorCode.INVALID_TARGET_AMOUNT_DATE); - } - - targetAmount.updateAmount(amount); - + TargetAmount targetAmount = targetAmountSaveService.updateTargetAmount(targetAmountId, amount); + return TargetAmountDto.TargetAmountInfo.from(targetAmount); } From bf66172e971693c82f57b2241f5b6a2364953c66 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:23:59 +0900 Subject: [PATCH 07/13] =?UTF-8?q?refactor:=20target=5Famount=5Fdelete=5Fse?= =?UTF-8?q?rvice()=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/TargetAmountDeleteService.java | 28 +++++++++++++++++++ .../ledger/usecase/TargetAmountUseCase.java | 23 +++------------ 2 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountDeleteService.java diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountDeleteService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountDeleteService.java new file mode 100644 index 000000000..57ba14fa4 --- /dev/null +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountDeleteService.java @@ -0,0 +1,28 @@ +package kr.co.pennyway.api.apis.ledger.service; + +import kr.co.pennyway.domain.domains.target.domain.TargetAmount; +import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; +import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; +import kr.co.pennyway.domain.domains.target.service.TargetAmountService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class TargetAmountDeleteService { + private final TargetAmountService targetAmountService; + + @Transactional + public void execute(Long targetAmountId) { + TargetAmount targetAmount = targetAmountService.readTargetAmount(targetAmountId) + .filter(TargetAmount::isAllocatedAmount) + .orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); + + if (!targetAmount.isThatMonth()) { + throw new TargetAmountErrorException(TargetAmountErrorCode.INVALID_TARGET_AMOUNT_DATE); + } + + targetAmountService.deleteTargetAmount(targetAmount); + } +} diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index a33de07fe..42ba2bfee 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -2,16 +2,12 @@ import kr.co.pennyway.api.apis.ledger.dto.TargetAmountDto; import kr.co.pennyway.api.apis.ledger.mapper.TargetAmountMapper; +import kr.co.pennyway.api.apis.ledger.service.TargetAmountDeleteService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountSaveService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountSearchService; import kr.co.pennyway.common.annotation.UseCase; import kr.co.pennyway.domain.common.redisson.DistributedLockPrefix; -import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.target.domain.TargetAmount; -import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; -import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; -import kr.co.pennyway.domain.domains.target.service.TargetAmountService; -import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.annotation.Transactional; @@ -23,12 +19,9 @@ @UseCase @RequiredArgsConstructor public class TargetAmountUseCase { - private final UserService userService; - private final TargetAmountService targetAmountService; - private final SpendingService spendingService; - private final TargetAmountSaveService targetAmountSaveService; private final TargetAmountSearchService targetAmountSearchService; + private final TargetAmountDeleteService targetAmountDeleteService; @Transactional public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year, int month) { @@ -55,20 +48,12 @@ public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) @Transactional public TargetAmountDto.TargetAmountInfo updateTargetAmount(Long targetAmountId, Integer amount) { TargetAmount targetAmount = targetAmountSaveService.updateTargetAmount(targetAmountId, amount); - + return TargetAmountDto.TargetAmountInfo.from(targetAmount); } @Transactional public void deleteTargetAmount(Long targetAmountId) { - TargetAmount targetAmount = targetAmountService.readTargetAmount(targetAmountId) - .filter(TargetAmount::isAllocatedAmount) - .orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); - - if (!targetAmount.isThatMonth()) { - throw new TargetAmountErrorException(TargetAmountErrorCode.INVALID_TARGET_AMOUNT_DATE); - } - - targetAmountService.deleteTargetAmount(targetAmount); + targetAmountDeleteService.execute(targetAmountId); } } From d51d5a3fd9429e8bc28587a309fd1fab5e05a6a0 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:34:36 +0900 Subject: [PATCH 08/13] =?UTF-8?q?style:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20transactional=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index 42ba2bfee..d8248883b 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -30,17 +30,14 @@ public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year return TargetAmountDto.TargetAmountInfo.from(targetAmount); } - @Transactional(readOnly = true) public TargetAmountDto.WithTotalSpendingRes getTargetAmountAndTotalSpending(Long userId, LocalDate date) { return targetAmountSearchService.readTargetAmountAndTotalSpending(userId, date); } - @Transactional(readOnly = true) public List getTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { return targetAmountSearchService.readTargetAmountsAndTotalSpendings(userId, date); } - @Transactional(readOnly = true) public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) { return TargetAmountMapper.toRecentTargetAmountResponse(targetAmountSearchService.readRecentTargetAmount(userId)); } @@ -52,7 +49,6 @@ public TargetAmountDto.TargetAmountInfo updateTargetAmount(Long targetAmountId, return TargetAmountDto.TargetAmountInfo.from(targetAmount); } - @Transactional public void deleteTargetAmount(Long targetAmountId) { targetAmountDeleteService.execute(targetAmountId); } From d2985fe12a62f6106b8bd0c2bb9d49ba76bbb211 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:28:43 +0900 Subject: [PATCH 09/13] =?UTF-8?q?refactor:=20=EC=9B=94=EB=B3=84=20?= =?UTF-8?q?=EC=B4=9D=20=EC=A7=80=EC=B6=9C=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger/service/SpendingSearchService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java index 19b7cd9be..c0c9c6866 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java @@ -4,20 +4,28 @@ import kr.co.pennyway.domain.common.repository.QueryHandler; import kr.co.pennyway.domain.domains.spending.domain.QSpending; import kr.co.pennyway.domain.domains.spending.domain.Spending; +import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.user.domain.QUser; +import kr.co.pennyway.domain.domains.user.domain.User; +import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; +import kr.co.pennyway.domain.domains.user.exception.UserErrorException; +import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.List; +import java.util.Optional; @Slf4j @Service @RequiredArgsConstructor public class SpendingSearchService { + private final UserService userService; private final SpendingService spendingService; private final QUser user = QUser.user; @@ -38,4 +46,16 @@ public List readSpendings(Long userId, int year, int month) { return spendingService.readSpendings(predicate, queryHandler, sort); } + + @Transactional(readOnly = true) + public Optional readTotalSpendingAmountByUserIdThatMonth(Long userId, LocalDate date) { + return spendingService.readTotalSpendingAmountByUserId(userId, date); + } + + @Transactional(readOnly = true) + public List readTotalSpendingsAmountByUserId(Long userId) { + User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); + + return spendingService.readTotalSpendingsAmountByUserId(userId); + } } From 1c3283eb7f2170ab88f9dfa4b9683e486d0a37d7 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:31:20 +0900 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20=EC=A7=80=EC=B6=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C,=20=EC=A7=80=EC=B6=9C=20=EB=AA=A9=ED=91=9C?= =?UTF-8?q?=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger/service/TargetAmountSearchService.java | 14 +++++--------- .../apis/ledger/usecase/TargetAmountUseCase.java | 10 +++++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java index 8882d1230..09eeb1272 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java @@ -18,7 +18,6 @@ import java.time.LocalDate; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -27,14 +26,6 @@ public class TargetAmountSearchService { private final SpendingService spendingService; private final TargetAmountService targetAmountService; - @Transactional(readOnly = true) - public TargetAmountDto.WithTotalSpendingRes readTargetAmountAndTotalSpending(Long userId, LocalDate date) { - TargetAmount targetAmount = targetAmountService.readTargetAmountThatMonth(userId, date).orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); - Optional totalSpending = spendingService.readTotalSpendingAmountByUserId(userId, date); - - return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); - } - @Transactional(readOnly = true) public List readTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); @@ -45,6 +36,11 @@ public List readTargetAmountsAndTotalSpend return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, user.getCreatedAt().toLocalDate(), date); } + @Transactional(readOnly = true) + public TargetAmount readTargetAmountThatMonth(Long userId, LocalDate date) { + return targetAmountService.readTargetAmountThatMonth(userId, date).orElseThrow(() -> new TargetAmountErrorException(TargetAmountErrorCode.NOT_FOUND_TARGET_AMOUNT)); + } + @Transactional(readOnly = true) public Integer readRecentTargetAmount(Long userId) { return targetAmountService.readRecentTargetAmount(userId) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index d8248883b..c498d5800 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -2,11 +2,13 @@ import kr.co.pennyway.api.apis.ledger.dto.TargetAmountDto; import kr.co.pennyway.api.apis.ledger.mapper.TargetAmountMapper; +import kr.co.pennyway.api.apis.ledger.service.SpendingSearchService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountDeleteService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountSaveService; import kr.co.pennyway.api.apis.ledger.service.TargetAmountSearchService; import kr.co.pennyway.common.annotation.UseCase; import kr.co.pennyway.domain.common.redisson.DistributedLockPrefix; +import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; import kr.co.pennyway.domain.domains.target.domain.TargetAmount; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,6 +16,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; @Slf4j @UseCase @@ -23,6 +26,8 @@ public class TargetAmountUseCase { private final TargetAmountSearchService targetAmountSearchService; private final TargetAmountDeleteService targetAmountDeleteService; + private final SpendingSearchService spendingSearchService; + @Transactional public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year, int month) { TargetAmount targetAmount = targetAmountSaveService.createTargetAmount(DistributedLockPrefix.TARGET_AMOUNT_USER, userId, LocalDate.of(year, month, 1)); @@ -30,8 +35,11 @@ public TargetAmountDto.TargetAmountInfo createTargetAmount(Long userId, int year return TargetAmountDto.TargetAmountInfo.from(targetAmount); } + @Transactional(readOnly = true) public TargetAmountDto.WithTotalSpendingRes getTargetAmountAndTotalSpending(Long userId, LocalDate date) { - return targetAmountSearchService.readTargetAmountAndTotalSpending(userId, date); + TargetAmount targetAmount = targetAmountSearchService.readTargetAmountThatMonth(userId, date); + Optional totalSpending = spendingSearchService.readTotalSpendingAmountByUserIdThatMonth(userId, date); + return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); } public List getTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { From 0c27dc3a6598c201a57ffcc7de1f616b59fcc342 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:42:38 +0900 Subject: [PATCH 11/13] =?UTF-8?q?refactor:=20=EB=AA=A9=ED=91=9C=EA=B8=88?= =?UTF-8?q?=EC=95=A1&=EC=9B=94=EB=B3=84=20=EC=A7=80=EC=B6=9C=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger/service/SpendingSearchService.java | 7 ------- .../service/TargetAmountSearchService.java | 19 ++----------------- .../ledger/usecase/TargetAmountUseCase.java | 12 +++++++++++- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java index c0c9c6866..b57febf61 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingSearchService.java @@ -7,10 +7,6 @@ import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.user.domain.QUser; -import kr.co.pennyway.domain.domains.user.domain.User; -import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; -import kr.co.pennyway.domain.domains.user.exception.UserErrorException; -import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Sort; @@ -25,7 +21,6 @@ @Service @RequiredArgsConstructor public class SpendingSearchService { - private final UserService userService; private final SpendingService spendingService; private final QUser user = QUser.user; @@ -54,8 +49,6 @@ public Optional readTotalSpendingAmountByUserIdThatMonth(Lo @Transactional(readOnly = true) public List readTotalSpendingsAmountByUserId(Long userId) { - User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); - return spendingService.readTotalSpendingsAmountByUserId(userId); } } diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java index 09eeb1272..711db65df 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/TargetAmountSearchService.java @@ -1,17 +1,9 @@ package kr.co.pennyway.api.apis.ledger.service; -import kr.co.pennyway.api.apis.ledger.dto.TargetAmountDto; -import kr.co.pennyway.api.apis.ledger.mapper.TargetAmountMapper; -import kr.co.pennyway.domain.domains.spending.dto.TotalSpendingAmount; -import kr.co.pennyway.domain.domains.spending.service.SpendingService; import kr.co.pennyway.domain.domains.target.domain.TargetAmount; import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorCode; import kr.co.pennyway.domain.domains.target.exception.TargetAmountErrorException; import kr.co.pennyway.domain.domains.target.service.TargetAmountService; -import kr.co.pennyway.domain.domains.user.domain.User; -import kr.co.pennyway.domain.domains.user.exception.UserErrorCode; -import kr.co.pennyway.domain.domains.user.exception.UserErrorException; -import kr.co.pennyway.domain.domains.user.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,18 +14,11 @@ @Service @RequiredArgsConstructor public class TargetAmountSearchService { - private final UserService userService; - private final SpendingService spendingService; private final TargetAmountService targetAmountService; @Transactional(readOnly = true) - public List readTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { - User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); - - List targetAmounts = targetAmountService.readTargetAmountsByUserId(userId); - List totalSpendings = spendingService.readTotalSpendingsAmountByUserId(userId); - - return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, user.getCreatedAt().toLocalDate(), date); + public List readTargetAmountsByUserId(Long userId) { + return targetAmountService.readTargetAmountsByUserId(userId); } @Transactional(readOnly = true) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index c498d5800..edd9b74d3 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -42,8 +42,18 @@ public TargetAmountDto.WithTotalSpendingRes getTargetAmountAndTotalSpending(Long return TargetAmountMapper.toWithTotalSpendingResponse(targetAmount, totalSpending.orElse(null), date); } + @Transactional(readOnly = true) public List getTargetAmountsAndTotalSpendings(Long userId, LocalDate date) { - return targetAmountSearchService.readTargetAmountsAndTotalSpendings(userId, date); + List targetAmounts = targetAmountSearchService.readTargetAmountsByUserId(userId); + List totalSpendings = spendingSearchService.readTotalSpendingsAmountByUserId(userId); + + // 소비 내역 중 가장 오래된 날짜를 기준으로 잡는다. + LocalDate startAt = totalSpendings.stream() + .map(totalSpendingAmount -> LocalDate.of(totalSpendingAmount.year(), totalSpendingAmount.month(), 1)) + .min(LocalDate::compareTo) + .orElse(LocalDate.now()); + + return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, startAt, date); } public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) { From a059df40aed97c8502fe5f7cae0a4142edb48730 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:04:03 +0900 Subject: [PATCH 12/13] =?UTF-8?q?fix:=20target=5Famount=5Fmapper=20start?= =?UTF-8?q?=5Fat=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=9D=BC=EC=9E=90=20->=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=98=A4=EB=9E=98=EB=90=9C=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ledger/mapper/TargetAmountMapper.java | 22 +++++++++++++++---- .../ledger/usecase/TargetAmountUseCase.java | 9 +++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/TargetAmountMapper.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/TargetAmountMapper.java index 62b9379d3..7e407a53c 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/TargetAmountMapper.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/TargetAmountMapper.java @@ -32,12 +32,13 @@ public static TargetAmountDto.WithTotalSpendingRes toWithTotalSpendingResponse(T /** * TargetAmount와 TotalSpendingAmount를 이용하여 WithTotalSpendingRes 리스트를 생성한다.
- * startAt부터 endAt까지의 날짜에 대한 WithTotalSpendingRes를 생성하며, 임의의 날짜에 대한 정보가 없을 경우 더미 데이터를 생성한다. + * startAt부터 endAt까지의 날짜에 대한 WithTotalSpendingRes를 생성하며, 임의의 날짜에 대한 정보가 없을 경우 더미 데이터를 생성한다.
+ * startAt은 목표 금액 데이터 중 가장 오래된 날짜를 기준으로 잡는다. * - * @param startAt : 조회 시작 날짜. 이유가 없다면 사용자 생성 날짜를 사용한다. - * @param endAt : 조회 종료 날짜. 이유가 없다면 현재 날짜이며, 클라이언트로 부터 받은 날짜를 사용한다. + * @param endAt : 조회 종료 날짜. 이유가 없다면 현재 날짜이며, 클라이언트로 부터 받은 날짜를 사용한다. */ - public static List toWithTotalSpendingResponses(List targetAmounts, List totalSpendings, LocalDate startAt, LocalDate endAt) { + public static List toWithTotalSpendingResponses(List targetAmounts, List totalSpendings, LocalDate endAt) { + LocalDate startAt = getOldestDate(targetAmounts); int monthLength = (endAt.getYear() - startAt.getYear()) * 12 + (endAt.getMonthValue() - startAt.getMonthValue()); Map targetAmountsByDates = toYearMonthMap(targetAmounts, targetAmount -> YearMonth.of(targetAmount.getCreatedAt().getYear(), targetAmount.getCreatedAt().getMonthValue()), Function.identity()); @@ -86,6 +87,19 @@ private static TargetAmountDto.WithTotalSpendingRes createWithTotalSpendingRes(T .build(); } + private static LocalDate getOldestDate(List targetAmounts) { + LocalDate minDate = LocalDate.now(); + + for (TargetAmount targetAmount : targetAmounts) { + LocalDate date = targetAmount.getCreatedAt().toLocalDate(); + if (date.isBefore(minDate)) { + minDate = date; + } + } + + return minDate; + } + /** * List를 YearMonth를 key로 하는 Map으로 변환한다. * diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java index edd9b74d3..cf6fa55f7 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/TargetAmountUseCase.java @@ -47,13 +47,10 @@ public List getTargetAmountsAndTotalSpendi List targetAmounts = targetAmountSearchService.readTargetAmountsByUserId(userId); List totalSpendings = spendingSearchService.readTotalSpendingsAmountByUserId(userId); - // 소비 내역 중 가장 오래된 날짜를 기준으로 잡는다. - LocalDate startAt = totalSpendings.stream() - .map(totalSpendingAmount -> LocalDate.of(totalSpendingAmount.year(), totalSpendingAmount.month(), 1)) - .min(LocalDate::compareTo) - .orElse(LocalDate.now()); + // 목표 금액 중 가장 오래된 날짜를 기준으로 잡는다. (마지막 원소) + LocalDate startAt = targetAmounts.get(targetAmounts.size() - 1).getCreatedAt().toLocalDate(); - return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, startAt, date); + return TargetAmountMapper.toWithTotalSpendingResponses(targetAmounts, totalSpendings, date); } public TargetAmountDto.RecentTargetAmountRes getRecentTargetAmount(Long userId) { From 2348bd2013e230a17558f2a66945ad9ed9695b46 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:05:15 +0900 Subject: [PATCH 13/13] =?UTF-8?q?docs:=20=EB=AA=A9=ED=91=9C=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EB=AC=B8=EC=84=9C=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/pennyway/api/apis/ledger/api/TargetAmountApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/api/TargetAmountApi.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/api/TargetAmountApi.java index eb4c081d0..3dd1e18ed 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/api/TargetAmountApi.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/api/TargetAmountApi.java @@ -59,7 +59,7 @@ public interface TargetAmountApi { }) ResponseEntity getTargetAmountAndTotalSpending(@PathVariable LocalDate date, @AuthenticationPrincipal SecurityUserDetails user); - @Operation(summary = "사용자 가입 이후 현재까지의 목표 금액 및 총 사용 금액 리스트 조회", method = "GET", description = "일수는 무시하고 년/월 정보만 사용한다. 데이터가 존재하지 않을 때 더미 값을 사용하며, 최신 데이터 순으로 정렬된 응답을 반환한다.") + @Operation(summary = "가장 오래된 목표 금액 이후부터 현재까지의 목표 금액 및 총 사용 금액 리스트 조회", method = "GET", description = "일수는 무시하고 년/월 정보만 사용한다. 데이터가 존재하지 않을 때 더미 값을 사용하며, 최신 데이터 순으로 정렬된 응답을 반환한다.") @Parameters({ @Parameter(name = "date", description = "현재 날짜(yyyy-MM-dd)", required = true, in = ParameterIn.QUERY), @Parameter(name = "param", hidden = true)