-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : 커리큘럼 ID로 키워드들 조회 API 구현 #1472
Merged
The head ref may contain hidden characters: "feature/1461-\uB85C\uB4DC\uB9F5_\uD0A4\uC6CC\uB4DC_\uBC18\uD658_\uAE30\uB2A5_\uCD94\uAC00"
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
package wooteco.prolog.roadmap.application; | ||
|
||
import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION; | ||
|
||
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.common.exception.BadRequestException; | ||
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 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); | ||
} | ||
} |
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
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 findRoadMapKeyword(@RequestParam final Long curriculumId) { | ||
return roadMapService.findAllKeywords(curriculumId); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
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.Collections; | ||
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() { | ||
//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); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeywordService에 넣지 않은 이유가 있을지 궁금합니다!