Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/Projects/BKData/Sources/Constant/APIConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ private final class BKDataBundleToken {}
enum APIConfig {
private static let bundle = Bundle(for: BKDataBundleToken.self)

/// API Base URL (xcconfig에서 /api까지만 포함)
private static let baseURL: String = {
/// V1 API Base URL (auth, books, users, home)
static let baseURL: String = {
guard let value = bundle.object(forInfoDictionaryKey: "BASE_API_URL") as? String else {
fatalError("Can't load environment: BKData.BASE_API_URL")
}
return value
}()

/// V1 API Base URL (auth, books, users, home)
static let baseURLv1: String = {
return baseURL + "/v1"
}()

/// V2 API Base URL (emotions, reading-records)
static let baseURLv2: String = {
return baseURL + "/v2"
// V1 URL에서 v2로 변경
return baseURL.replacingOccurrences(of: "/api/v1", with: "/api/v2")
}()
Comment on lines 19 to 22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

문자열 치환 방식이 취약합니다 — baseURL/api/v1이 없으면 V2 URL이 V1과 동일해집니다.

replacingOccurrences는 패턴이 없을 경우 원본 문자열을 그대로 반환합니다. 환경 설정 오류나 URL 형식 변경 시 V2 엔드포인트가 V1 API를 호출하게 되어 런타임에 발견하기 어려운 버그가 발생할 수 있습니다.

치환 결과를 검증하는 assertion을 추가하는 것을 권장합니다.

🛡️ 방어적 검증 추가 제안
 static let baseURLv2: String = {
-    // V1 URL에서 v2로 변경
-    return baseURL.replacingOccurrences(of: "/api/v1", with: "/api/v2")
+    let v2URL = baseURL.replacingOccurrences(of: "/api/v1", with: "/api/v2")
+    assert(v2URL != baseURL, "baseURL에 '/api/v1' 경로가 포함되어 있지 않습니다. BASE_API_URL 환경 설정을 확인하세요.")
+    return v2URL
 }()
🤖 Prompt for AI Agents
In `@src/Projects/BKData/Sources/Constant/APIConfig.swift` around lines 19 - 22,
현재 baseURLv2 클로저는 baseURL.replacingOccurrences(of: "/api/v1", with: "/api/v2") 만
호출하므로 치환이 실패하면 동일한 V1 URL을 반환합니다; baseURLv2 초기화 로직(심볼: baseURLv2, 참조: baseURL,
replacingOccurrences)을 수정해 치환 결과가 실제로 "/api/v2"를 포함하는지 검사하는 assertion 또는 guard를
추가하고(예: 치환 전후 비교 또는 contains 검사), 실패 시 명확한 오류/로그 또는 런타임 실패를 발생시키도록 변경해 잘못된 환경설정이
조기에 드러나게 하세요.

}
4 changes: 0 additions & 4 deletions src/Projects/BKData/Sources/DataAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ public struct DataAssembly: Assembly {
)
}

container.register(type: ExternalLinkRepository.self) { _ in
return DefaultExternalLinkRepository()
}

container.register(
type: EmotionRepository.self,
scope: .singleton
Expand Down
11 changes: 11 additions & 0 deletions src/Projects/BKDomain/Sources/Entity/PrimaryEmotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ public enum PrimaryEmotion: String, CaseIterable, Codable {
case .other: return .other
}
}

/// Emotion에서 변환
public static func from(emotion: Emotion) -> PrimaryEmotion {
switch emotion {
case .warmth: return .warmth
case .joy: return .joy
case .sad: return .sadness
case .insight: return .insight
case .other: return .other
}
}
}
Loading
Loading