Skip to content

Commit 4e2e18f

Browse files
committed
[Refactor] 시나리오 Service ã�JSON Helper 메서드 구현
1 parent a461451 commit 4e2e18f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

back/src/main/java/com/back/domain/scenario/service/ScenarioService.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.back.domain.scenario.repository.SceneTypeRepository;
1313
import com.back.global.exception.ApiException;
1414
import com.back.global.exception.ErrorCode;
15+
import com.fasterxml.jackson.databind.ObjectMapper;
1516
import lombok.RequiredArgsConstructor;
1617
import org.springframework.scheduling.annotation.Async;
1718
import org.springframework.stereotype.Service;
@@ -39,6 +40,9 @@ public class ScenarioService {
3940
private final DecisionLineRepository decisionLineRepository;
4041
private final BaseLineRepository baseLineRepository;
4142

43+
// Object Mapper 주입
44+
private final ObjectMapper objectMapper;
45+
4246
// AI Service 주입 (추후 구현 시 필요, AI 호출용)
4347
// private final AiService aiService;
4448

@@ -372,15 +376,20 @@ private List<MockDecisionNode> createMockDecisionNodes() {
372376
);
373377
}
374378

375-
// JSON 파싱 메서드 (추후 구현)
379+
// JSON 파싱 Helper 메서드
376380
private Map<String, String> parseTimelineTitles(String timelineTitles) {
377-
// TODO: 실제 JSON 파싱 구현 (ObjectMapper 사용)
378-
// 현재는 Mock 데이터 반환
379-
return Map.of(
380-
"2020", "창업 도전",
381-
"2022", "해외 진출",
382-
"2025", "상장 성공"
383-
);
381+
try {
382+
// Null 이나 빈 문자열 체크
383+
if (timelineTitles == null || timelineTitles.trim().isEmpty()) {
384+
throw new ApiException(ErrorCode.SCENARIO_TIMELINE_NOT_FOUND);
385+
}
386+
387+
// JSON 문자열을 Map으로 파싱
388+
return objectMapper.readValue(timelineTitles, Map.class);
389+
} catch (Exception e) {
390+
// JSON 파싱 실패 시 예외 처리
391+
throw new ApiException(ErrorCode.SCENARIO_TIMELINE_NOT_FOUND);
392+
}
384393
}
385394

386395
// 시나리오 비교 분석

back/src/main/java/com/back/global/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum ErrorCode {
5050
SCENE_TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "SC004", "Scene Type Not Found"),
5151
SCENARIO_ALREADY_IN_PROGRESS(HttpStatus.CONFLICT, "SC005", "Scenario Already In Progress"),
5252
BASE_SCENARIO_NOT_FOUND(HttpStatus.NOT_FOUND, "SC006", "Base Scenario Not Found"),
53+
SCENARIO_TIMELINE_NOT_FOUND(HttpStatus.NOT_FOUND, "SC007", "Scenario Timeline Not Found"),
5354

5455
// Like Errors
5556
LIKE_NOT_FOUND(HttpStatus.NOT_FOUND, "L001", "Like Not Found"),

0 commit comments

Comments
 (0)