-
Notifications
You must be signed in to change notification settings - Fork 0
fix(qa): QA 이슈 수정 및 룰렛 보상 초기 데이터 추가 #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
196 changes: 196 additions & 0 deletions
196
...-service/src/main/java/com/comatching/item/global/init/RouletteRewardDataInitializer.java
This file contains hidden or 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,196 @@ | ||
| package com.comatching.item.global.init; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.comatching.item.domain.roulette.entity.RouletteReward; | ||
| import com.comatching.item.domain.roulette.enums.RewardType; | ||
| import com.comatching.item.domain.roulette.enums.RouletteType; | ||
| import com.comatching.item.domain.roulette.repository.RouletteRewardRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class RouletteRewardDataInitializer implements CommandLineRunner { | ||
|
|
||
| private final RouletteRewardRepository rouletteRewardRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void run(String... args) throws Exception { | ||
| if (rouletteRewardRepository.count() > 0) { | ||
| log.info("[RouletteRewardDataInitializer] 이미 룰렛 보상 데이터가 존재하여 초기화를 건너뜁니다."); | ||
| return; | ||
| } | ||
|
|
||
| log.info("[RouletteRewardDataInitializer] 초기 룰렛 보상 데이터를 생성합니다..."); | ||
|
|
||
| List<RouletteReward> rewards = List.of( | ||
|
|
||
| // FREE Roulette | ||
| reward( | ||
| RouletteType.FREE, | ||
| "옵션권 1장", | ||
| RewardType.OPTION_TICKET, | ||
| 1, | ||
| 1, | ||
| 4500, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.FREE, | ||
| "옵션권 2장", | ||
| RewardType.OPTION_TICKET, | ||
| 2, | ||
| 4501, | ||
| 7000, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.FREE, | ||
| "꽝", | ||
| RewardType.NONE, | ||
| 0, | ||
| 7001, | ||
| 8500, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.FREE, | ||
| "뽑기권 1장", | ||
| RewardType.MATCHING_TICKET, | ||
| 1, | ||
| 8501, | ||
| 9700, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.FREE, | ||
| "풀세트", | ||
| RewardType.FULL_SET, | ||
| 0, | ||
| 9701, | ||
| 10000, | ||
| null | ||
| ), | ||
|
|
||
| // SPECIAL Roulette | ||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "옵션권 2장", | ||
| RewardType.OPTION_TICKET, | ||
| 2, | ||
| 1, | ||
| 3900, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "옵션권 5장", | ||
| RewardType.OPTION_TICKET, | ||
| 5, | ||
| 3901, | ||
| 6400, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "뽑기권 1장", | ||
| RewardType.MATCHING_TICKET, | ||
| 1, | ||
| 6401, | ||
| 8400, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "풀세트", | ||
| RewardType.FULL_SET, | ||
| 0, | ||
| 8401, | ||
| 9400, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "뽑기권 5장", | ||
| RewardType.MATCHING_TICKET, | ||
| 5, | ||
| 9401, | ||
| 9600, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "뽑기권 10장", | ||
| RewardType.MATCHING_TICKET, | ||
| 10, | ||
| 9601, | ||
| 9750, | ||
| null | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "1만원권 상품권", | ||
| RewardType.GIFT_CARD, | ||
| 0, | ||
| 9751, | ||
| 9900, | ||
| 999 | ||
| ), | ||
|
|
||
| reward( | ||
| RouletteType.SPECIAL, | ||
| "2만원권 상품권", | ||
| RewardType.GIFT_CARD, | ||
| 0, | ||
| 9901, | ||
| 10000, | ||
| 999 | ||
| ) | ||
| ); | ||
|
|
||
| rouletteRewardRepository.saveAll(rewards); | ||
|
|
||
| log.info( | ||
| "[RouletteRewardDataInitializer] 룰렛 보상 {}개 생성 완료.", | ||
| rewards.size() | ||
| ); | ||
| } | ||
|
|
||
| private RouletteReward reward( | ||
| RouletteType rouletteType, | ||
| String rewardName, | ||
| RewardType rewardType, | ||
| int quantity, | ||
| int rangeStart, | ||
| int rangeEnd, | ||
| Integer remainingCount | ||
| ) { | ||
| return RouletteReward.builder() | ||
| .rouletteType(rouletteType) | ||
| .rewardName(rewardName) | ||
| .rewardType(rewardType) | ||
| .quantity(quantity) | ||
| .rangeStart(rangeStart) | ||
| .rangeEnd(rangeEnd) | ||
| .remainingCount(remainingCount) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OCP 위반: 특정 상품 코드가 서비스 레이어에 하드코딩됨
DISCOUNT_MATCHING_TICKET_1이라는 특정 상품 코드를 문자열 비교로 두 군데에 특례 처리하고 있습니다.purchaseCountPurchasable() || DISCOUNT_MATCHING_TICKET_CODE.equals(product.code()))DISCOUNT_MATCHING_TICKET_CODE.equals(...) && quantity != 1)왜 문제인가: 이 서비스는 이미 "상품별 한정 판매 규칙"을 일반화해서 모델링하는 패턴이 있습니다 —
Product엔티티의firstPurchaseOnly플래그와, 그걸 소비하는validatePurchaseCountLimit의 제네릭 분기가 그 예입니다. 이번 변경은 그 패턴을 재사용하지 않고 특정 product code 문자열을 서비스 레이어에 직접 박아 넣는 새로운 특례를 추가했습니다. docs/code-review-guidelines.md 의 OCP 기준("조건문으로 분기되는 로직이 전략 패턴 등으로 분리 가능한지 검토합니다")에 해당하는 사례로, 다음에 "소진돼도 계속 노출", "1회 수량 제한" 같은 규칙을 가진 상품이 추가될 때마다 이 두 지점에if (CODE.equals(...))분기가 계속 늘어나는 구조입니다.개선 방향:
Product엔티티에alwaysListedWhenExhausted(또는 유사한 이름) /maxQuantityPerOrder같은 필드를 추가해 상품 데이터로 표현하고,ShopServiceImpl은 특정 코드 문자열이 아니라 그 필드를 제네릭하게 검사하도록 바꾸는 것을 제안합니다. 필드 추가와 초기화 데이터(ShopDataInitializer) 변경이 함께 필요해 커밋 가능한 제안(suggestion block)으로 바로 반영하기는 어려워 설명으로만 남깁니다.