Blockers: - IYmtgTests: replace ScannerViewModel() (no-arg init removed) with CollectionViewModel() in testViewModelFiltering and testPortfolioCalculation - IYmtgTests: fix property access — scannedList, librarySearchText, filteredList, portfolioValue all live on CollectionViewModel, not ScannerViewModel; inject test data after async init settles Major: - ContentView: update .onChange(of:) to two-parameter closure syntax (iOS 17 deprecation) - ModelManager: add missing import FirebaseCore so FirebaseApp.app() resolves explicitly - CollectionViewModel.deleteCard: call CloudEngine.delete(card:) to remove Firebase entry when a card is deleted (prevents data accumulation) - CloudEngine: remove never-called batchUpdatePrices() — full backup already handled by backupAllToFirebase() Minor: - CardDetailView: move to Features/CardDetail/CardDetailView.swift; remove from ContentView.swift - Delete PersistenceActor.swift placeholder (superseded by PersistenceController.swift) - AppConfig.validate(): broaden placeholder-email guard to catch empty strings and common fake domains - ModelManager: document OTA restart requirement in code comment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.8 KiB
Swift
50 lines
1.8 KiB
Swift
import FirebaseFirestore
|
|
import FirebaseAuth
|
|
|
|
// MARK: - CLOUD ENGINE
|
|
class CloudEngine {
|
|
static var db: Firestore? {
|
|
return FirebaseApp.app() != nil ? Firestore.firestore() : nil
|
|
}
|
|
|
|
static func signInSilently() {
|
|
guard FirebaseApp.app() != nil else { return }
|
|
if Auth.auth().currentUser == nil { Auth.auth().signInAnonymously() }
|
|
}
|
|
|
|
static func save(card: SavedCard) async {
|
|
guard let db = db, let uid = Auth.auth().currentUser?.uid else { return }
|
|
let data: [String: Any] = [
|
|
"name": card.name,
|
|
"set": card.setCode,
|
|
"num": card.collectorNumber,
|
|
"val": card.currentValuation ?? 0.0,
|
|
"cond": card.condition,
|
|
"foil": card.foilType,
|
|
"coll": card.collectionName,
|
|
"loc": card.storageLocation,
|
|
"grade": card.grade ?? "",
|
|
"svc": card.gradingService ?? "",
|
|
"cert": card.certNumber ?? "",
|
|
"date": card.dateAdded,
|
|
"curr": card.currencyCode ?? "USD",
|
|
"rarity": card.rarity ?? "",
|
|
"colors": card.colorIdentity ?? [],
|
|
"ser": card.isSerialized ?? false,
|
|
"img": card.imageFileName,
|
|
"custom": card.isCustomValuation
|
|
]
|
|
do {
|
|
try await db.collection("users").document(uid).collection("inventory").document(card.id.uuidString).setData(data, merge: true)
|
|
} catch { print("Cloud Save Error: \(error)") }
|
|
}
|
|
|
|
static func delete(card: SavedCard) async {
|
|
guard let db = db, let uid = Auth.auth().currentUser?.uid else { return }
|
|
do {
|
|
try await db.collection("users").document(uid).collection("inventory").document(card.id.uuidString).delete()
|
|
} catch { print("Cloud Delete Error: \(error)") }
|
|
}
|
|
|
|
}
|