From b976bcce95b181dd6437f05695c9a55556233f56 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:01:45 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=A7=20=EC=A7=80=EC=B6=9C?= =?UTF-8?q?=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=9C=A0=EC=A6=88?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 배포 파이프라인 이미지 빌드 버전 추가 * refactor: spending_category create 유즈케이스 리팩토링 * refactor: get_spending_categories usecase 리팩토링 --- .../ledger/mapper/SpendingCategoryMapper.java | 21 ++++++++++++++ .../service/SpendingCategorySaveService.java | 28 +++++++++++++++++++ .../SpendingCategorySearchService.java | 22 +++++++++++++++ .../usecase/SpendingCategoryUseCase.java | 25 ++++++----------- 4 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/SpendingCategoryMapper.java create mode 100644 pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySaveService.java create mode 100644 pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySearchService.java diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/SpendingCategoryMapper.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/SpendingCategoryMapper.java new file mode 100644 index 000000000..7f27d3f99 --- /dev/null +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/SpendingCategoryMapper.java @@ -0,0 +1,21 @@ +package kr.co.pennyway.api.apis.ledger.mapper; + +import kr.co.pennyway.api.apis.ledger.dto.SpendingCategoryDto; +import kr.co.pennyway.common.annotation.Mapper; +import kr.co.pennyway.domain.domains.spending.domain.SpendingCustomCategory; +import kr.co.pennyway.domain.domains.spending.dto.CategoryInfo; + +import java.util.List; + +@Mapper +public class SpendingCategoryMapper { + public static SpendingCategoryDto.Res toResponse(SpendingCustomCategory category) { + return SpendingCategoryDto.Res.from(CategoryInfo.of(category.getId(), category.getName(), category.getIcon())); + } + + public static List toResponses(List categories) { + return categories.stream() + .map(SpendingCategoryMapper::toResponse) + .toList(); + } +} diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySaveService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySaveService.java new file mode 100644 index 000000000..d916dea0c --- /dev/null +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySaveService.java @@ -0,0 +1,28 @@ +package kr.co.pennyway.api.apis.ledger.service; + +import kr.co.pennyway.domain.domains.spending.domain.SpendingCustomCategory; +import kr.co.pennyway.domain.domains.spending.service.SpendingCustomCategoryService; +import kr.co.pennyway.domain.domains.spending.type.SpendingCategory; +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; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Service +@RequiredArgsConstructor +public class SpendingCategorySaveService { + private final UserService userService; + private final SpendingCustomCategoryService spendingCustomCategoryService; + + @Transactional + public SpendingCustomCategory execute(Long userId, String categoryName, SpendingCategory icon) { + User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); + + return spendingCustomCategoryService.createSpendingCustomCategory(SpendingCustomCategory.of(categoryName, icon, user)); + } +} diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySearchService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySearchService.java new file mode 100644 index 000000000..a27b1c2a8 --- /dev/null +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySearchService.java @@ -0,0 +1,22 @@ +package kr.co.pennyway.api.apis.ledger.service; + +import kr.co.pennyway.domain.domains.spending.domain.SpendingCustomCategory; +import kr.co.pennyway.domain.domains.spending.service.SpendingCustomCategoryService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor +public class SpendingCategorySearchService { + private final SpendingCustomCategoryService spendingCustomCategoryService; + + @Transactional(readOnly = true) + public List readSpendingCustomCategories(Long userId) { + return spendingCustomCategoryService.readSpendingCustomCategories(userId); + } +} diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/SpendingCategoryUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/SpendingCategoryUseCase.java index f8cdfb824..2ecb83c85 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/SpendingCategoryUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/ledger/usecase/SpendingCategoryUseCase.java @@ -1,15 +1,12 @@ package kr.co.pennyway.api.apis.ledger.usecase; import kr.co.pennyway.api.apis.ledger.dto.SpendingCategoryDto; +import kr.co.pennyway.api.apis.ledger.mapper.SpendingCategoryMapper; +import kr.co.pennyway.api.apis.ledger.service.SpendingCategorySaveService; +import kr.co.pennyway.api.apis.ledger.service.SpendingCategorySearchService; import kr.co.pennyway.common.annotation.UseCase; import kr.co.pennyway.domain.domains.spending.domain.SpendingCustomCategory; -import kr.co.pennyway.domain.domains.spending.dto.CategoryInfo; -import kr.co.pennyway.domain.domains.spending.service.SpendingCustomCategoryService; import kr.co.pennyway.domain.domains.spending.type.SpendingCategory; -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.transaction.annotation.Transactional; @@ -20,24 +17,20 @@ @UseCase @RequiredArgsConstructor public class SpendingCategoryUseCase { - private final UserService userService; - private final SpendingCustomCategoryService spendingCustomCategoryService; + private final SpendingCategorySaveService spendingCategorySaveService; + private final SpendingCategorySearchService spendingCategorySearchService; @Transactional public SpendingCategoryDto.Res createSpendingCategory(Long userId, String categoryName, SpendingCategory icon) { - User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND)); + SpendingCustomCategory category = spendingCategorySaveService.execute(userId, categoryName, icon); - SpendingCustomCategory category = spendingCustomCategoryService.createSpendingCustomCategory(SpendingCustomCategory.of(categoryName, icon, user)); - - return SpendingCategoryDto.Res.from(CategoryInfo.of(category.getId(), category.getName(), category.getIcon())); + return SpendingCategoryMapper.toResponse(category); } @Transactional(readOnly = true) public List getSpendingCategories(Long userId) { - List categories = spendingCustomCategoryService.readSpendingCustomCategories(userId); + List categories = spendingCategorySearchService.readSpendingCustomCategories(userId); - return categories.stream() - .map(category -> SpendingCategoryDto.Res.from(CategoryInfo.of(category.getId(), category.getName(), category.getIcon()))) - .toList(); + return SpendingCategoryMapper.toResponses(categories); } }