-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 🔧 지출 카테고리 유즈케이스 리팩토링 (#114)
* fix: 배포 파이프라인 이미지 빌드 버전 추가 * refactor: spending_category create 유즈케이스 리팩토링 * refactor: get_spending_categories usecase 리팩토링
- Loading branch information
1 parent
9b69bd4
commit b976bcc
Showing
4 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...ernal-api/src/main/java/kr/co/pennyway/api/apis/ledger/mapper/SpendingCategoryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SpendingCategoryDto.Res> toResponses(List<SpendingCustomCategory> categories) { | ||
return categories.stream() | ||
.map(SpendingCategoryMapper::toResponse) | ||
.toList(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...api/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySaveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...i/src/main/java/kr/co/pennyway/api/apis/ledger/service/SpendingCategorySearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SpendingCustomCategory> readSpendingCustomCategories(Long userId) { | ||
return spendingCustomCategoryService.readSpendingCustomCategories(userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters