Skip to content

Commit

Permalink
fix: 진행 중인 챌린지 취소 시, 챌린지 현황의 시작 전 개수가 증가하는 버그 픽스
Browse files Browse the repository at this point in the history
- JoinStatus가 NO(실패)일 때에, 챌린지 현황 조회에 포함되도록 로직 수정
- 챌린지 현황 조회에 사용하는 HashMap의 Key에 시작 전에 해당하는 READY 포함
- for문(반복문)을 Iterator로 변경 및 indent를 2에서 1로 감소
  • Loading branch information
SSung023 committed Jun 27, 2024
1 parent 5c18745 commit 369a10d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main/java/com/genius/gitget/profile/service/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.genius.gitget.challenge.participant.domain.JoinResult.FAIL;
import static com.genius.gitget.challenge.participant.domain.JoinResult.PROCESSING;
import static com.genius.gitget.challenge.participant.domain.JoinResult.READY;
import static com.genius.gitget.challenge.participant.domain.JoinResult.SUCCESS;
import static com.genius.gitget.challenge.participant.domain.JoinStatus.YES;

Expand Down Expand Up @@ -135,34 +136,34 @@ public UserChallengeResultResponse getUserChallengeResult(User user) {
User findUser = getUserByIdentifier(user.getIdentifier());
HashMap<JoinResult, List<Long>> participantHashMap = new HashMap<>() {
{
put(READY, new ArrayList<>());
put(FAIL, new ArrayList<>());
put(PROCESSING, new ArrayList<>());
put(SUCCESS, new ArrayList<>());
}
};
List<Participant> participantInfoList = findUser.getParticipantList(); // 유저의 참여 정보를 담고 있는 리스트
int participanTotalCount = participantInfoList.size();

for (int i = 0; i < participantInfoList.size(); i++) { // 각 참여 정보를 받아옴.
if (participantInfoList.get(i).getJoinStatus() == YES) {
JoinResult joinResult = participantInfoList.get(i).getJoinResult();
if (participantHashMap.containsKey(joinResult)) { // hashmap에 저장된 key와 일치 여부 확인
List<Long> participantIdList = participantHashMap.get(joinResult);
participantIdList.add(participantInfoList.get(i).getId()); // 일치한다면, 해당 key의 value인 list에 id 저장
participantHashMap.put(joinResult, participantIdList); // 최종적으로 hashmap에 저장
}
List<Participant> participantInfos = findUser.getParticipantList();
for (Participant participant : participantInfos) {
JoinResult joinResult = participant.getJoinResult();
if (!participantHashMap.containsKey(joinResult)) {
continue;
}

List<Long> participantIds = participantHashMap.get(joinResult);
participantIds.add(participant.getId());
participantHashMap.put(joinResult, participantIds);
}

int beforeStart = participantHashMap.get(READY).size();
int fail = participantHashMap.get(FAIL).size();
int success = participantHashMap.get(SUCCESS).size();
int processing = participantHashMap.get(PROCESSING).size();

return UserChallengeResultResponse.builder()
.beforeStart(beforeStart)
.fail(fail)
.success(success)
.processing(processing)
.beforeStart(participanTotalCount - fail - success - processing)
.build();
}

Expand Down

0 comments on commit 369a10d

Please sign in to comment.