Skip to content

Commit

Permalink
refactor: Dto -> Map 변환 로직 Stream API 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Nov 23, 2023
1 parent 4e1ad8e commit 0469d57
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndDoneQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndTotalQuizCount;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Objects.isNull;
import static java.util.stream.Collectors.toMap;

@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -34,25 +33,18 @@ public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, fin
}

private Map<Long, Integer> getTotalQuizCounts() {
final Map<Long, Integer> totalQuizCounts = new HashMap<>();

for (KeywordIdAndTotalQuizCount totalQuizCount : keywordRepository.findTotalQuizCount()) {
totalQuizCounts.put(totalQuizCount.getKeywordId(), totalQuizCount.getTotalQuizCount());
}

return totalQuizCounts;
return keywordRepository.findTotalQuizCount().stream()
.collect(
toMap(
KeywordIdAndTotalQuizCount::getKeywordId,
KeywordIdAndTotalQuizCount::getTotalQuizCount));
}

private Map<Long, Integer> getDoneQuizCounts(final Long memberId) {
final Map<Long, Integer> doneQuizCounts = new HashMap<>();
if (isNull(memberId)) {
return doneQuizCounts;
}

for (KeywordIdAndDoneQuizCount doneQuizCount : keywordRepository.findDoneQuizCountByMemberId(memberId)) {
doneQuizCounts.put(doneQuizCount.getKeywordId(), doneQuizCount.getDoneQuizCount());
}

return doneQuizCounts;
return keywordRepository.findDoneQuizCountByMemberId(memberId).stream()
.collect(
toMap(
KeywordIdAndDoneQuizCount::getKeywordId,
KeywordIdAndDoneQuizCount::getDoneQuizCount));
}
}

0 comments on commit 0469d57

Please sign in to comment.