Skip to content

Commit

Permalink
style: doneQuizCount -> answeredQuizCount로 용어 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Nov 23, 2023
1 parent 5455a51 commit 8a9faff
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import wooteco.prolog.roadmap.application.dto.KeywordsResponse;
import wooteco.prolog.roadmap.domain.Keyword;
import wooteco.prolog.roadmap.domain.repository.KeywordRepository;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndDoneQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndAnsweredQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndTotalQuizCount;

import java.util.List;
Expand All @@ -24,10 +24,10 @@ public class RoadMapService {
public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, final Long memberId) {
final List<Keyword> keywords = keywordRepository.findAllByCurriculumId(curriculumId);
final Map<Long, Integer> totalQuizCounts = getTotalQuizCounts();
final Map<Long, Integer> doneQuizCounts = getDoneQuizCounts(memberId);
final Map<Long, Integer> answeredQuizCounts = getAnsweredQuizCounts(memberId);

final KeywordsResponse keywordsResponse = KeywordsResponse.of(keywords);
keywordsResponse.setProgress(totalQuizCounts, doneQuizCounts);
keywordsResponse.setProgress(totalQuizCounts, answeredQuizCounts);

return keywordsResponse;
}
Expand All @@ -40,11 +40,11 @@ private Map<Long, Integer> getTotalQuizCounts() {
KeywordIdAndTotalQuizCount::getTotalQuizCount));
}

private Map<Long, Integer> getDoneQuizCounts(final Long memberId) {
return keywordRepository.findDoneQuizCountByMemberId(memberId).stream()
private Map<Long, Integer> getAnsweredQuizCounts(final Long memberId) {
return keywordRepository.findAnsweredQuizCountByMemberId(memberId).stream()
.collect(
toMap(
KeywordIdAndDoneQuizCount::getKeywordId,
KeywordIdAndDoneQuizCount::getDoneQuizCount));
KeywordIdAndAnsweredQuizCount::getKeywordId,
KeywordIdAndAnsweredQuizCount::getAnsweredQuizCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private static List<KeywordResponse> createChildren(final Set<Keyword> children)
.collect(Collectors.toList());
}

public void setProgress(final Map<Long, Integer> totalQuizCounts, final Map<Long, Integer> doneQuizCounts) {
public void setProgress(final Map<Long, Integer> totalQuizCounts, final Map<Long, Integer> answeredQuizCounts) {
totalQuizCount = totalQuizCounts.getOrDefault(keywordId, 0);
doneQuizCount = doneQuizCounts.getOrDefault(keywordId, 0);
doneQuizCount = answeredQuizCounts.getOrDefault(keywordId, 0);

childrenKeywords.forEach(child -> child.setProgress(totalQuizCounts, doneQuizCounts));
childrenKeywords.forEach(child -> child.setProgress(totalQuizCounts, answeredQuizCounts));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static KeywordsResponse of(final List<Keyword> keywords) {
return new KeywordsResponse(keywordsResponse);
}

public void setProgress(final Map<Long, Integer> totalQuizCounts, final Map<Long, Integer> doneQuizCounts) {
data.forEach(response -> response.setProgress(totalQuizCounts, doneQuizCounts));
public void setProgress(final Map<Long, Integer> totalQuizCounts, final Map<Long, Integer> answeredQuizCounts) {
data.forEach(response -> response.setProgress(totalQuizCounts, answeredQuizCounts));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import wooteco.prolog.roadmap.domain.Keyword;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndDoneQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndAnsweredQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndTotalQuizCount;

import java.util.List;
Expand All @@ -17,13 +17,13 @@ public interface KeywordRepository extends JpaRepository<Keyword, Long> {
"GROUP BY k.id")
List<KeywordIdAndTotalQuizCount> findTotalQuizCount();

@Query("SELECT k.id AS keywordId, COUNT (e.id) AS doneQuizCount " +
@Query("SELECT k.id AS keywordId, COUNT (e.id) AS answeredQuizCount " +
"FROM Keyword k " +
"JOIN Quiz q ON k.id = q.keyword.id " +
"JOIN EssayAnswer e ON e.quiz.id = q.id " +
"WHERE e.member.id = :memberId " +
"GROUP BY k.id ")
List<KeywordIdAndDoneQuizCount> findDoneQuizCountByMemberId(@Param("memberId") Long memberId);
List<KeywordIdAndAnsweredQuizCount> findAnsweredQuizCountByMemberId(@Param("memberId") Long memberId);

Keyword findFetchByIdOrderBySeq(@Param("keywordId") Long keywordId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package wooteco.prolog.roadmap.domain.repository.dto;

public interface KeywordIdAndDoneQuizCount {
public interface KeywordIdAndAnsweredQuizCount {
long getKeywordId();

int getDoneQuizCount();
int getAnsweredQuizCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ void findAllKeywordsWithProgress() {
roots.hasSize(2)
.satisfies(containsKeywordIds(root1.getId(), root2.getId()))
.satisfies(containsTotalQuizCounts(0, 1))
.satisfies(containsDoneQuizCounts(0, 0));
.satisfies(containsAnsweredQuizCounts(0, 0));

oneDepthChildren.hasSize(1)
.satisfies(containsKeywordIds(oneDepthChild.getId()))
.satisfies(containsTotalQuizCounts(1))
.satisfies(containsDoneQuizCounts(0));
.satisfies(containsAnsweredQuizCounts(0));

twoDepthChildren.hasSize(1)
.satisfies(containsKeywordIds(twoDepthChild.getId()))
.satisfies(containsTotalQuizCounts(0))
.satisfies(containsDoneQuizCounts(0));
.satisfies(containsAnsweredQuizCounts(0));
});
}

Expand Down Expand Up @@ -137,21 +137,21 @@ void findAllKeywordsWithProgress_login() {
roots.hasSize(2)
.satisfies(containsKeywordIds(root1.getId(), root2.getId()))
.satisfies(containsTotalQuizCounts(0, 1))
.satisfies(containsDoneQuizCounts(0, 1));
.satisfies(containsAnsweredQuizCounts(0, 1));

oneDepthChildren.hasSize(1)
.satisfies(containsKeywordIds(oneDepthChild.getId()))
.satisfies(containsTotalQuizCounts(1))
.satisfies(containsDoneQuizCounts(0));
.satisfies(containsAnsweredQuizCounts(0));

twoDepthChildren.hasSize(1)
.satisfies(containsKeywordIds(twoDepthChild.getId()))
.satisfies(containsTotalQuizCounts(1))
.satisfies(containsDoneQuizCounts(1));
.satisfies(containsAnsweredQuizCounts(1));
});
}

private Consumer<List<? extends KeywordResponse>> containsDoneQuizCounts(final Integer... expected) {
private Consumer<List<? extends KeywordResponse>> containsAnsweredQuizCounts(final Integer... expected) {
return keywords -> assertThat(keywords)
.map(KeywordResponse::getDoneQuizCount)
.containsExactlyInAnyOrder(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import wooteco.prolog.roadmap.domain.repository.EssayAnswerRepository;
import wooteco.prolog.roadmap.domain.repository.KeywordRepository;
import wooteco.prolog.roadmap.domain.repository.QuizRepository;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndDoneQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndAnsweredQuizCount;
import wooteco.prolog.roadmap.domain.repository.dto.KeywordIdAndTotalQuizCount;
import wooteco.prolog.session.domain.Session;
import wooteco.prolog.session.domain.repository.SessionRepository;
Expand Down Expand Up @@ -121,7 +121,7 @@ class KeywordRepositoryTest {
sessionId);

// then
assertThat(extractParentKeyword.size()).isEqualTo(1);
assertThat(extractParentKeyword).hasSize(1);
}

@Test
Expand Down Expand Up @@ -219,15 +219,15 @@ void findDoneQuizCountByMemberId() {
essayAnswerRepository.save(new EssayAnswer(quiz2, "쓰라고 해서요ㅠ", member));

//when
final List<KeywordIdAndDoneQuizCount> doneQuizCounts = keywordRepository.findDoneQuizCountByMemberId(member.getId());
final List<KeywordIdAndAnsweredQuizCount> doneQuizCounts = keywordRepository.findAnsweredQuizCountByMemberId(member.getId());

//then
assertSoftly(softAssertions -> {
softAssertions.assertThat(doneQuizCounts)
.map(KeywordIdAndDoneQuizCount::getKeywordId)
.map(KeywordIdAndAnsweredQuizCount::getKeywordId)
.containsExactly(parent.getId());
softAssertions.assertThat(doneQuizCounts)
.map(KeywordIdAndDoneQuizCount::getDoneQuizCount)
.map(KeywordIdAndAnsweredQuizCount::getAnsweredQuizCount)
.containsExactly(2);
});
}
Expand Down

0 comments on commit 8a9faff

Please sign in to comment.