|
29 | 29 | import java.time.LocalDate; |
30 | 30 | import java.util.ArrayList; |
31 | 31 | import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | +import java.util.stream.Collectors; |
32 | 34 | import lombok.RequiredArgsConstructor; |
33 | 35 | import org.springframework.stereotype.Service; |
34 | 36 | import org.springframework.transaction.annotation.Transactional; |
@@ -83,12 +85,24 @@ public List<AllProblemGetResponse> getAllProblem(Long memberId, int year, int mo |
83 | 85 | Long publishId = publish.getId(); |
84 | 86 | LocalDate date = publish.getPublishedDate(); |
85 | 87 |
|
86 | | - // 날짜별 사용자 제출 정보 조회 |
| 88 | + // 문항세트의 전체 문제 목록 조회 |
| 89 | + ProblemSet problemSet = problemSetRepository.findByIdElseThrow(publish.getProblemSetId()); |
| 90 | + List<Long> problemIds = problemSet.getProblemIds(); |
| 91 | + |
| 92 | + // 사용자 제출 정보 조회 |
87 | 93 | List<ProblemSubmit> submissions = problemSubmitRepository.findByMemberIdAndPublishId(memberId, publishId); |
88 | | - List<ProblemSubmitStatus> problemStatuses = submissions.stream() |
89 | | - .map(ProblemSubmit::getStatus) |
| 94 | + Map<Long, ProblemSubmitStatus> submitStatusMap = submissions.stream() |
| 95 | + .collect(Collectors.toMap( |
| 96 | + ProblemSubmit::getProblemId, |
| 97 | + ProblemSubmit::getStatus |
| 98 | + )); |
| 99 | + |
| 100 | + // 모든 문항에 대해 상태 리스트 구성 |
| 101 | + List<ProblemSubmitStatus> problemStatuses = problemIds.stream() |
| 102 | + .map(id -> submitStatusMap.getOrDefault(id, ProblemSubmitStatus.NOT_STARTED)) |
90 | 103 | .toList(); |
91 | 104 |
|
| 105 | + |
92 | 106 | // 사용자 제출 정보 바탕으로 진행도 결정 |
93 | 107 | DayProgress progress = DayProgress.determineDayProgress(problemStatuses); |
94 | 108 | String mainProblemImageUrl = getMainProblemImageUrl(publish.getProblemSetId()); |
|
0 commit comments