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
3 changes: 2 additions & 1 deletion Configuration/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -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=***

Expand Down
3 changes: 2 additions & 1 deletion Configuration/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -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=***

Expand Down
2 changes: 1 addition & 1 deletion Foodiary/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<key>CFBundleVersion</key>
<string>2</string>
<key>CUSTOM_API_BASE_URL</key>
<string>$(CUSTOM_API_BASE_URL)</string>
<string>$(API_SCHEME)://$(API_HOST)</string>
<key>CUSTOM_API_TOKEN</key>
<string>$(CUSTOM_API_TOKEN)</string>
<key>FATSECRET_CONSUMER_KEY</key>
Expand Down
18 changes: 10 additions & 8 deletions Foodiary/Services/FoodDatabase/FoodSearchService.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
]

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 1 addition & 26 deletions Foodiary/Views/MealPlan/FoodResultCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
}
}
Loading