-
Notifications
You must be signed in to change notification settings - Fork 4
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
improve: 산책 저장 시 부여되는 뱃지 확인 로직 #368
base: dev
Are you sure you want to change the base?
Conversation
Update CI/CD infra (Docker,GitHub Action) & Swagger 적용
Fix: gradle.yml
Update gradleDeployMaster.yml
Update and rename gradle.yml to gradleDev.yml
Update gradleDeployMaster.yml and gradleDeployDev.yml
Update gradleDeployMaster.yml
Update gradleDeployMaster.yml and gradleDeployDev.yml
fix: Security-Server yml version
Chore : Update Security YAML
improve: 산책 저장 시 부여되는 뱃지 확인 로직
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.
리뷰 남겼습니다
두서 없이 작성해서 이해안되는 부분은 다시 알려주세요!~
public List<Integer> getAcquiredBadgeIdxList(int userIdx, Double totalDistance, Integer totalWalkCount) { | ||
// 현재 누적 거리, 횟수로 얻을 수 있는 뱃지 계산 - 획득한 뱃지가 없을 때 어떤 동작을 해야 하지? | ||
TotalDistanceStatus distanceStatus = TotalDistanceStatus.getDistanceBadge(totalDistance).orElseThrow(); | ||
TotalRecordStatus recordStatus = TotalRecordStatus.getWalkCountBadge(totalWalkCount).orElseThrow(); |
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.
음.. 현재 생각나는건 enum이 현재는 2개로 분리되어 있는데(record, distance) 이것들을 하나로 합치고(뭐 DefaultBadgeStatus 등등..) 여기에 start 뱃지를 넣어서 이걸 반환하는 방법이 있을 것 같아요 (근데 이거는 좀 별로인 것 같긴 하네요.)
아니면 그냥 Optional로 놔두다가 274번째줄 이후에 둘 다 empty면 바로 반환하는 방법도 있을 것 같아요.
처음이면 1만 넣어서 반환, 아니면 빈 리스트로 반환
List<Integer> acquiredBadgeIdxList = new ArrayList<>(); | ||
|
||
// 현재 갖고 있는 뱃지 조회 | ||
List<Integer> beforeSavingWalkBadgeList = userBadgeRepository.findAllByUserIdxAndStatus(userIdx, "ACTIVE") |
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.
findAllByUserIdxAndStatus 반환 값이 Optional<List<>> 형태인데
Optional을 빼고 그냥 List<> 형태로 반환하면 어떨까요?
반환 값이 없으면 빈 리스트로 나오는게 자연스러울 것 같아서요!
} | ||
} | ||
|
||
return acquiredBadgeIdxList; |
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.
return acquiredBadgeIdxList; | |
return Collections.unmodifiableList(acquiredBadgeIdxList); |
메서드 밖에서 리스트에 추가 못하게 불변 리스트로 반환하는 것도 좋을 것 같아요
int originMaxRecordBadgeIdx = 1; // 원래 갖고 있던 뱃지(6~8)의 가장 큰 값 | ||
|
||
for (Integer originBadgeIdx : beforeSavingWalkBadgeList) { | ||
if (originBadgeIdx >= TotalDistanceStatus.minBadgeIdx() && originBadgeIdx <= TotalDistanceStatus.maxBadgeIdx()) { |
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.
if 문 안에 있는 boolean 값을 TotalDistanceStatus 안에 넣는건 어떻게 생각하시나요?
List<Integer> beforeSavingWalkBadgeList = userBadgeRepository.findAllByUserIdxAndStatus(userIdx, "ACTIVE") | ||
.map(userBadgeList -> userBadgeList.stream() | ||
.map(UserBadge::getBadgeIdx) | ||
.sorted() |
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.
정렬을 하는 이유가 뭔가요?
for (Integer originBadgeIdx : beforeSavingWalkBadgeList) { | ||
if (originBadgeIdx >= TotalDistanceStatus.minBadgeIdx() && originBadgeIdx <= TotalDistanceStatus.maxBadgeIdx()) { | ||
originMaxDistanceBadgeIdx = originBadgeIdx; | ||
} | ||
if (originBadgeIdx >= TotalRecordStatus.minBadgeIdx() && originBadgeIdx <= TotalRecordStatus.maxBadgeIdx()) { | ||
originMaxRecordBadgeIdx = originBadgeIdx; | ||
} | ||
} |
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.
앞에서 beforeSavingWalkBadgeList을 만들 떄 내림차순으로 정렬하고
originMaxDistanceBadgeIdx, originMaxRecordBadgeIdx 이게 초기화 되면
바로 for 문을 나가는건 어떤가요?
for (Integer originBadgeIdx : beforeSavingWalkBadgeList) { | |
if (originBadgeIdx >= TotalDistanceStatus.minBadgeIdx() && originBadgeIdx <= TotalDistanceStatus.maxBadgeIdx()) { | |
originMaxDistanceBadgeIdx = originBadgeIdx; | |
} | |
if (originBadgeIdx >= TotalRecordStatus.minBadgeIdx() && originBadgeIdx <= TotalRecordStatus.maxBadgeIdx()) { | |
originMaxRecordBadgeIdx = originBadgeIdx; | |
} | |
} | |
for (Integer originBadgeIdx : beforeSavingWalkBadgeList) { | |
if (originBadgeIdx >= TotalDistanceStatus.minBadgeIdx() && originBadgeIdx <= TotalDistanceStatus.maxBadgeIdx()) { | |
originMaxDistanceBadgeIdx = originBadgeIdx; | |
} | |
else if (originBadgeIdx >= TotalRecordStatus.minBadgeIdx() && originBadgeIdx <= TotalRecordStatus.maxBadgeIdx()) { | |
originMaxRecordBadgeIdx = originBadgeIdx; | |
} | |
if (originMaxDistanceBadgeIdx != 1 && originMaxRecordBadgeIdx != 1) break; | |
} |
if(distanceStatus.getBadgeIdx() > originMaxDistanceBadgeIdx) { | ||
for (int i = originMaxDistanceBadgeIdx + 1; i <= distanceStatus.getBadgeIdx(); i++) { | ||
acquiredBadgeIdxList.add(i); | ||
} | ||
} | ||
|
||
//거리 뱃지 확인 로직 - 2~5 | ||
if(recordStatus.getBadgeIdx() > originMaxRecordBadgeIdx) { | ||
for (int i = originMaxRecordBadgeIdx + 1; i <= recordStatus.getBadgeIdx(); i++) { | ||
acquiredBadgeIdxList.add(i); | ||
} | ||
} |
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.
안드한테 순서대로 보내려면 두 개 순서 바꿔야 할 것 같아요
변경한 부분
코드리뷰 시 함께 고민해줬으면 좋겠는 부분 (?)
완벽하진 않지만 우선 지금까지 한 부분만 올릴게용!
그리고 추가적으로 더 할 수 있으면 계속 수정하겠습니다 :)