-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ff6c20
commit df92752
Showing
6 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/wooteco/prolog/roadmap/application/RoadMapService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package wooteco.prolog.roadmap.application; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import wooteco.prolog.roadmap.application.dto.KeywordsResponse; | ||
import wooteco.prolog.roadmap.domain.Curriculum; | ||
import wooteco.prolog.roadmap.domain.Keyword; | ||
import wooteco.prolog.roadmap.domain.repository.CurriculumRepository; | ||
import wooteco.prolog.roadmap.domain.repository.KeywordRepository; | ||
import wooteco.prolog.session.domain.Session; | ||
import wooteco.prolog.session.domain.repository.SessionRepository; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class RoadMapService { | ||
|
||
private final CurriculumRepository curriculumRepository; | ||
private final SessionRepository sessionRepository; | ||
private final KeywordRepository keywordRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public KeywordsResponse findAllKeywords(final Long curriculumId) { | ||
final Curriculum curriculum = curriculumRepository.findById(curriculumId) | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
"해당 커리큘럼이 존재하지 않습니다. curriculumId = " + curriculumId)); | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/wooteco/prolog/roadmap/ui/RoadmapController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package wooteco.prolog.roadmap.ui; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wooteco.prolog.roadmap.application.RoadMapService; | ||
import wooteco.prolog.roadmap.application.dto.KeywordsResponse; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class RoadmapController { | ||
|
||
private final RoadMapService roadMapService; | ||
|
||
@GetMapping("/roadmaps") | ||
public KeywordsResponse findKeywords(@RequestParam final Long curriculumId) { | ||
return roadMapService.findAllKeywords(curriculumId); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
backend/src/test/java/wooteco/prolog/roadmap/application/RoadMapServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package wooteco.prolog.roadmap.application; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import wooteco.prolog.roadmap.application.dto.KeywordsResponse; | ||
import wooteco.prolog.roadmap.domain.Curriculum; | ||
import wooteco.prolog.roadmap.domain.Keyword; | ||
import wooteco.prolog.roadmap.domain.repository.CurriculumRepository; | ||
import wooteco.prolog.roadmap.domain.repository.KeywordRepository; | ||
import wooteco.prolog.session.domain.Session; | ||
import wooteco.prolog.session.domain.repository.SessionRepository; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RoadMapServiceTest { | ||
|
||
@Mock | ||
private CurriculumRepository curriculumRepository; | ||
@Mock | ||
private SessionRepository sessionRepository; | ||
@Mock | ||
private KeywordRepository keywordRepository; | ||
@InjectMocks | ||
private RoadMapService roadMapService; | ||
|
||
@Test | ||
@DisplayName("curriculumId가 주어지면 해당 커리큘럼의 키워드들을 전부 조회할 수 있다.") | ||
void findAllKeywords() throws Exception { | ||
//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 = Keyword.createKeyword("자바1", "자바 설명1", 1, 5, session.getId(), | ||
null); | ||
|
||
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.createResponse(Arrays.asList(keyword)); | ||
|
||
//when | ||
final KeywordsResponse actual = | ||
roadMapService.findAllKeywords(curriculum.getId()); | ||
|
||
//then | ||
assertThat(actual) | ||
.usingRecursiveComparison() | ||
.isEqualTo(expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters