Skip to content

Commit 8b0d8b3

Browse files
committed
refactor : 최상위 keyword인지 도메인에서 판단하기
#1461
1 parent d45a3d6 commit 8b0d8b3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package wooteco.prolog.roadmap.application;
22

3+
import static wooteco.prolog.common.exception.BadRequestCode.CURRICULUM_NOT_FOUND_EXCEPTION;
4+
35
import java.util.List;
46
import java.util.Set;
57
import java.util.stream.Collectors;
68
import lombok.RequiredArgsConstructor;
79
import org.springframework.stereotype.Service;
810
import org.springframework.transaction.annotation.Transactional;
11+
import wooteco.prolog.common.exception.BadRequestException;
912
import wooteco.prolog.roadmap.application.dto.KeywordsResponse;
1013
import wooteco.prolog.roadmap.domain.Curriculum;
1114
import wooteco.prolog.roadmap.domain.Keyword;
@@ -26,8 +29,7 @@ public class RoadMapService {
2629
@Transactional(readOnly = true)
2730
public KeywordsResponse findAllKeywords(final Long curriculumId) {
2831
final Curriculum curriculum = curriculumRepository.findById(curriculumId)
29-
.orElseThrow(() -> new IllegalArgumentException(
30-
"해당 커리큘럼이 존재하지 않습니다. curriculumId = " + curriculumId));
32+
.orElseThrow(() -> new BadRequestException(CURRICULUM_NOT_FOUND_EXCEPTION));
3133

3234
final Set<Long> sessionIds = sessionRepository.findAllByCurriculumId(curriculum.getId())
3335
.stream()

backend/src/main/java/wooteco/prolog/roadmap/application/dto/KeywordsResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static KeywordsResponse createResponse(final List<Keyword> keywords) {
2626

2727
public static KeywordsResponse createResponseWithChildren(final List<Keyword> keywords) {
2828
List<KeywordResponse> keywordsResponse = keywords.stream()
29-
.filter(it -> it.getParent() == null)
29+
.filter(Keyword::isRoot)
3030
.map(KeywordResponse::createWithAllChildResponse)
3131
.collect(Collectors.toList());
3232
return new KeywordsResponse(keywordsResponse);

backend/src/main/java/wooteco/prolog/roadmap/domain/Keyword.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ private void validateKeywordParent(final Keyword parentKeyword) {
124124
}
125125
}
126126

127+
public boolean isRoot() {
128+
return parent == null;
129+
}
130+
127131
public Long getParentIdOrNull() {
128132
if (parent == null) {
129133
return null;

0 commit comments

Comments
 (0)