Skip to content

Commit

Permalink
feat: 전체 키워드 조회 API 학습 진도 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Aug 17, 2023
1 parent 69eff3a commit bb25ea3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ public class RoadMapService {
private final QuizRepository quizRepository;
private final EssayAnswerRepository essayAnswerRepository;

@Transactional(readOnly = true)
public KeywordsResponse findAllKeywords(final Long curriculumId) {
final Curriculum curriculum = curriculumRepository.findById(curriculumId)
.orElseThrow(() -> new BadRequestException(CURRICULUM_NOT_FOUND_EXCEPTION));

final Set<Long> sessionIds = sessionRepository.findAllByCurriculumId(curriculum.getId())
.stream()
.map(Session::getId)
.collect(Collectors.toSet());

final List<Keyword> keywords = keywordRepository.findBySessionIdIn(sessionIds);

return KeywordsResponse.createResponseWithChildren(keywords);
}

@Transactional(readOnly = true)
public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, final Long memberId) {
final Curriculum curriculum = curriculumRepository.findById(curriculumId)
Expand All @@ -73,8 +58,8 @@ public KeywordsResponse findAllKeywordsWithProgress(final Long curriculumId, fin
}

private KeywordsResponse createWithProgress(final List<Keyword> keywords,
final Map<Keyword, Set<Quiz>> quizzesPerKeyword,
final Set<Quiz> doneQuizzes) {
final Map<Keyword, Set<Quiz>> quizzesPerKeyword,
final Set<Quiz> doneQuizzes) {
final List<KeywordResponse> keywordResponses = keywords.stream()
.filter(Keyword::isRoot)
.map(keyword -> createWithProgress(keyword, quizzesPerKeyword, doneQuizzes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import wooteco.prolog.login.domain.AuthMemberPrincipal;
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.roadmap.application.RoadMapService;
import wooteco.prolog.roadmap.application.dto.KeywordsResponse;

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

@GetMapping("/roadmaps")
public KeywordsResponse findRoadMapKeyword(@RequestParam final Long curriculumId) {
return roadMapService.findAllKeywords(curriculumId);
public KeywordsResponse findRoadMapKeyword(@AuthMemberPrincipal final LoginMember member,
@RequestParam final Long curriculumId) {
return roadMapService.findAllKeywordsWithProgress(curriculumId, member.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,6 @@ class RoadMapServiceTest {
@InjectMocks
private RoadMapService roadMapService;

@Test
@DisplayName("curriculumId가 주어지면 해당 커리큘럼의 키워드들을 전부 조회할 수 있다.")
void findAllKeywords() {
//given
final Curriculum curriculum = new Curriculum(1L, "커리큘럼1");
final Session session = new Session(1L, curriculum.getId(), "세션1");
final List<Session> sessions = Arrays.asList(session);
final Keyword keyword = new Keyword(1L, "자바1", "자바 설명1", 1, 5, session.getId(),
null, Collections.emptySet());

when(curriculumRepository.findById(anyLong()))
.thenReturn(Optional.of(curriculum));

when(sessionRepository.findAllByCurriculumId(anyLong()))
.thenReturn(sessions);

when(keywordRepository.findBySessionIdIn(any()))
.thenReturn(Arrays.asList(keyword));

final KeywordsResponse expected = KeywordsResponse.createResponseWithChildren(Arrays.asList(keyword));

//when
final KeywordsResponse actual =
roadMapService.findAllKeywords(curriculum.getId());

//then
assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected);
}

@Test
@DisplayName("curriculumId가 주어지면 해당 커리큘럼의 키워드들을 학습 진도와 함께 전부 조회할 수 있다.")
void findAllKeywordsWithProgress() {
Expand Down

0 comments on commit bb25ea3

Please sign in to comment.