diff --git a/Configuration/Debug.xcconfig b/Configuration/Debug.xcconfig index efdaa9e..5921a93 100644 --- a/Configuration/Debug.xcconfig +++ b/Configuration/Debug.xcconfig @@ -1,7 +1,8 @@ // Foodiary API Keys FATSECRET_CONSUMER_KEY=275778613b5648e7a73ce4f1100c41f5 FATSECRET_CONSUMER_SECRET=1f1bdd9122e744709c5bdf91bb1f176a -CUSTOM_API_BASE_URL=https://foodiary-api.anyapp.my +API_SCHEME = https; +API_HOST = foodiary-api.anyapp.my; CUSTOM_API_TOKEN=0de67146d99696dae07cd8dea84bbaac2600361e18fccb57d9355aec41e330bf USDA_API_KEY=*** diff --git a/Configuration/Release.xcconfig b/Configuration/Release.xcconfig index 5624290..35b7b7b 100644 --- a/Configuration/Release.xcconfig +++ b/Configuration/Release.xcconfig @@ -1,7 +1,8 @@ // Foodiary API Keys FATSECRET_CONSUMER_KEY=275778613b5648e7a73ce4f1100c41f5 FATSECRET_CONSUMER_SECRET=1f1bdd9122e744709c5bdf91bb1f176a -CUSTOM_API_BASE_URL=https://foodiary-api.anyapp.my +API_SCHEME = https; +API_HOST = foodiary-api.anyapp.my; CUSTOM_API_TOKEN=0de67146d99696dae07cd8dea84bbaac2600361e18fccb57d9355aec41e330bf USDA_API_KEY=*** diff --git a/Foodiary/Info.plist b/Foodiary/Info.plist index 5e6a974..4fa41e2 100644 --- a/Foodiary/Info.plist +++ b/Foodiary/Info.plist @@ -26,7 +26,7 @@ CFBundleVersion 2 CUSTOM_API_BASE_URL - $(CUSTOM_API_BASE_URL) + $(API_SCHEME)://$(API_HOST) CUSTOM_API_TOKEN $(CUSTOM_API_TOKEN) FATSECRET_CONSUMER_KEY diff --git a/Foodiary/Services/FoodDatabase/FoodSearchService.swift b/Foodiary/Services/FoodDatabase/FoodSearchService.swift index c38435b..a8a4c5f 100644 --- a/Foodiary/Services/FoodDatabase/FoodSearchService.swift +++ b/Foodiary/Services/FoodDatabase/FoodSearchService.swift @@ -1,8 +1,10 @@ import Foundation -/// Facade that queries multiple food database providers in parallel and merges results. +/// Facade that queries the configured food database provider(s) and merges results. /// -/// **Priority order:** FatSecret (primary) → Custom API (fallback) → USDA (deactivated). +/// **Active provider:** Custom API (foodiary-api.anyapp.my) — sole source. +/// **Detached:** FatSecret (code preserved, endpoint no longer called). +/// **Deactivated:** USDA (code preserved). /// /// Usage: /// ```swift @@ -21,8 +23,8 @@ enum FoodSearchService { /// Only configured providers are queried. To deactivate a provider, /// leave its credentials empty in xcconfig. private static let allProviders: [any FoodDatabaseProvider] = [ - FatSecretService(), // Primary — FatSecret Basic API - CustomAPIService(), // Fallback — our own API (placeholder, no-op until built) + CustomAPIService(), // Primary — our own API (foodiary-api.anyapp.my) + // FatSecretService(), // Detached 2026-07-08 — code preserved at FoodDatabase/FatSecretService.swift // USDAService(), // Deactivated — code preserved at FoodDatabase/USDAService.swift ] @@ -31,7 +33,7 @@ enum FoodSearchService { allProviders.filter { provider in switch provider.source { case .fatsecret: - return FoodDatabaseConfig.isFatSecretConfigured + return false // Detached 2026-07-08 — code preserved, endpoint no longer queried case .custom: return FoodDatabaseConfig.isCustomAPIConfigured case .usda: @@ -56,7 +58,7 @@ enum FoodSearchService { let providers = activeProviders guard !providers.isEmpty else { - throw FoodDatabaseError.notConfigured(.fatsecret) + throw FoodDatabaseError.notConfigured(.custom) } // Query all providers in parallel @@ -124,8 +126,8 @@ enum FoodSearchService { private static func mergeResults( _ providerResults: [(source: FoodDatabaseSource, results: [FoodSearchResult])] ) -> [FoodSearchResult] { - // Priority order: FatSecret → Custom → (inactive sources last) - let priorityOrder: [FoodDatabaseSource] = [.fatsecret, .custom, .usda, .openFoodFacts] + // Priority order: Custom (primary) → FatSecret → (inactive sources last) + let priorityOrder: [FoodDatabaseSource] = [.custom, .fatsecret, .usda, .openFoodFacts] let sorted = providerResults.sorted { a, b in let ap = priorityOrder.firstIndex(of: a.source) ?? 999 let bp = priorityOrder.firstIndex(of: b.source) ?? 999 diff --git a/Foodiary/Views/MealPlan/FoodResultCard.swift b/Foodiary/Views/MealPlan/FoodResultCard.swift index 592f30d..821b284 100644 --- a/Foodiary/Views/MealPlan/FoodResultCard.swift +++ b/Foodiary/Views/MealPlan/FoodResultCard.swift @@ -8,9 +8,8 @@ struct FoodResultCard: View { var body: some View { VStack(alignment: .leading, spacing: 14) { - // Header: source badge + name + serving + // Header: name + serving VStack(alignment: .leading, spacing: 4) { - SourceBadge(source: result.source) Text(result.name) .font(.system(size: 16, weight: .bold)) .foregroundColor(FoodiaryDesign.pulseInk) @@ -144,27 +143,3 @@ private struct MacroTile: View { .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(FoodiaryDesign.pulseSurfaceSoft)) } } - -// MARK: - Source Badge - -private struct SourceBadge: View { - let source: FoodDatabaseSource - - private var color: Color { - switch source { - case .fatsecret: return FoodiaryDesign.pulseMint - case .custom: return FoodiaryDesign.pulsePrimary - case .usda: return FoodiaryDesign.pulseAmber - case .openFoodFacts: return Color(hex: "7C3AED") - } - } - - var body: some View { - Text(source.sourceDisplayName) - .font(.system(size: 9, weight: .bold)) - .foregroundColor(color) - .padding(.horizontal, 8) - .padding(.vertical, 3) - .background(RoundedRectangle(cornerRadius: 6).fill(color.opacity(0.12))) - } -}