Skip to content

Commit bb25ea3

Browse files
committed
feat: 전체 키워드 조회 API 학습 진도 기능 추가
1 parent 69eff3a commit bb25ea3

File tree

3 files changed

+7
-50
lines changed

3 files changed

+7
-50
lines changed

backend/src/main/java/wooteco/prolog/roadmap/application/RoadMapService.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ public class RoadMapService {
3535
private final QuizRepository quizRepository;
3636
private final EssayAnswerRepository essayAnswerRepository;
3737

38-
@Transactional(readOnly = true)
39-
public KeywordsResponse findAllKeywords(final Long curriculumId) {
40-
final Curriculum curriculum = curriculumRepository.findById(curriculumId)
41-
.orElseThrow(() -> new BadRequestException(CURRICULUM_NOT_FOUND_EXCEPTION));
42-
43-
final Set<Long> sessionIds = sessionRepository.findAllByCurriculumId(curriculum.getId())
44-
.stream()
45-
.map(Session::getId)
46-
.collect(Collectors.toSet());
47-
48-
final List<Keyword> keywords = keywordRepository.findBySessionIdIn(sessionIds);
49-
50-
return KeywordsResponse.createResponseWithChildren(keywords);
51-
}
52-
5338
@Transactional(readOnly = true)
5439
public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, final Long memberId) {
5540
final Curriculum curriculum = curriculumRepository.findById(curriculumId)
@@ -73,8 +58,8 @@ public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, fin
7358
}
7459

7560
private KeywordsResponse createWithProgress(final List<Keyword> keywords,
76-
final Map<Keyword, Set<Quiz>> quizzesPerKeyword,
77-
final Set<Quiz> doneQuizzes) {
61+
final Map<Keyword, Set<Quiz>> quizzesPerKeyword,
62+
final Set<Quiz> doneQuizzes) {
7863
final List<KeywordResponse> keywordResponses = keywords.stream()
7964
.filter(Keyword::isRoot)
8065
.map(keyword -> createWithProgress(keyword, quizzesPerKeyword, doneQuizzes))

backend/src/main/java/wooteco/prolog/roadmap/ui/RoadmapController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.springframework.web.bind.annotation.GetMapping;
55
import org.springframework.web.bind.annotation.RequestParam;
66
import org.springframework.web.bind.annotation.RestController;
7+
import wooteco.prolog.login.domain.AuthMemberPrincipal;
8+
import wooteco.prolog.login.ui.LoginMember;
79
import wooteco.prolog.roadmap.application.RoadMapService;
810
import wooteco.prolog.roadmap.application.dto.KeywordsResponse;
911

@@ -14,7 +16,8 @@ public class RoadmapController {
1416
private final RoadMapService roadMapService;
1517

1618
@GetMapping("/roadmaps")
17-
public KeywordsResponse findRoadMapKeyword(@RequestParam final Long curriculumId) {
18-
return roadMapService.findAllKeywords(curriculumId);
19+
public KeywordsResponse findRoadMapKeyword(@AuthMemberPrincipal final LoginMember member,
20+
@RequestParam final Long curriculumId) {
21+
return roadMapService.findAllKeywordsWithProgress(curriculumId, member.getId());
1922
}
2023
}

backend/src/test/java/wooteco/prolog/roadmap/application/RoadMapServiceTest.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,6 @@ class RoadMapServiceTest {
4949
@InjectMocks
5050
private RoadMapService roadMapService;
5151

52-
@Test
53-
@DisplayName("curriculumId가 주어지면 해당 커리큘럼의 키워드들을 전부 조회할 수 있다.")
54-
void findAllKeywords() {
55-
//given
56-
final Curriculum curriculum = new Curriculum(1L, "커리큘럼1");
57-
final Session session = new Session(1L, curriculum.getId(), "세션1");
58-
final List<Session> sessions = Arrays.asList(session);
59-
final Keyword keyword = new Keyword(1L, "자바1", "자바 설명1", 1, 5, session.getId(),
60-
null, Collections.emptySet());
61-
62-
when(curriculumRepository.findById(anyLong()))
63-
.thenReturn(Optional.of(curriculum));
64-
65-
when(sessionRepository.findAllByCurriculumId(anyLong()))
66-
.thenReturn(sessions);
67-
68-
when(keywordRepository.findBySessionIdIn(any()))
69-
.thenReturn(Arrays.asList(keyword));
70-
71-
final KeywordsResponse expected = KeywordsResponse.createResponseWithChildren(Arrays.asList(keyword));
72-
73-
//when
74-
final KeywordsResponse actual =
75-
roadMapService.findAllKeywords(curriculum.getId());
76-
77-
//then
78-
assertThat(actual)
79-
.usingRecursiveComparison()
80-
.isEqualTo(expected);
81-
}
82-
8352
@Test
8453
@DisplayName("curriculumId가 주어지면 해당 커리큘럼의 키워드들을 학습 진도와 함께 전부 조회할 수 있다.")
8554
void findAllKeywordsWithProgress() {

0 commit comments

Comments
 (0)