refactor: change domain model IDs from UUID to String canonical IDs
This refactor fixes the achievement system by using stable canonical string IDs (e.g., "stadium_mlb_fenway_park") instead of random UUIDs. This ensures stadium mappings for achievements are consistent across app launches and CloudKit sync operations. Changes: - Stadium, Team, Game: id property changed from UUID to String - Trip, TripStop, TripPreferences: updated to use String IDs for games/stadiums - CKModels: removed UUID parsing, use canonical IDs directly - AchievementEngine: now matches against canonical stadium IDs - All test files updated to use String IDs instead of UUID() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,18 +165,18 @@ actor CloudKitService {
|
||||
let ckGame = CKGame(record: record)
|
||||
|
||||
guard let homeRef = record[CKGame.homeTeamRefKey] as? CKRecord.Reference,
|
||||
let awayRef = record[CKGame.awayTeamRefKey] as? CKRecord.Reference,
|
||||
let homeId = UUID(uuidString: homeRef.recordID.recordName),
|
||||
let awayId = UUID(uuidString: awayRef.recordID.recordName)
|
||||
let awayRef = record[CKGame.awayTeamRefKey] as? CKRecord.Reference
|
||||
else { return nil }
|
||||
|
||||
let homeId = homeRef.recordID.recordName
|
||||
let awayId = awayRef.recordID.recordName
|
||||
|
||||
// Stadium ref is optional - use placeholder if not present
|
||||
let stadiumId: UUID
|
||||
if let stadiumRef = record[CKGame.stadiumRefKey] as? CKRecord.Reference,
|
||||
let refId = UUID(uuidString: stadiumRef.recordID.recordName) {
|
||||
stadiumId = refId
|
||||
let stadiumId: String
|
||||
if let stadiumRef = record[CKGame.stadiumRefKey] as? CKRecord.Reference {
|
||||
stadiumId = stadiumRef.recordID.recordName
|
||||
} else {
|
||||
stadiumId = UUID() // Placeholder - will be resolved via team lookup
|
||||
stadiumId = "stadium_placeholder_\(UUID().uuidString)" // Placeholder - will be resolved via team lookup
|
||||
}
|
||||
|
||||
return ckGame.game(homeTeamId: homeId, awayTeamId: awayId, stadiumId: stadiumId)
|
||||
@@ -188,8 +188,8 @@ actor CloudKitService {
|
||||
return allGames.sorted { $0.dateTime < $1.dateTime }
|
||||
}
|
||||
|
||||
func fetchGame(by id: UUID) async throws -> Game? {
|
||||
let predicate = NSPredicate(format: "gameId == %@", id.uuidString)
|
||||
func fetchGame(by id: String) async throws -> Game? {
|
||||
let predicate = NSPredicate(format: "gameId == %@", id)
|
||||
let query = CKQuery(recordType: CKRecordType.game, predicate: predicate)
|
||||
|
||||
let (results, _) = try await publicDatabase.records(matching: query)
|
||||
@@ -201,12 +201,13 @@ actor CloudKitService {
|
||||
|
||||
guard let homeRef = record[CKGame.homeTeamRefKey] as? CKRecord.Reference,
|
||||
let awayRef = record[CKGame.awayTeamRefKey] as? CKRecord.Reference,
|
||||
let stadiumRef = record[CKGame.stadiumRefKey] as? CKRecord.Reference,
|
||||
let homeId = UUID(uuidString: homeRef.recordID.recordName),
|
||||
let awayId = UUID(uuidString: awayRef.recordID.recordName),
|
||||
let stadiumId = UUID(uuidString: stadiumRef.recordID.recordName)
|
||||
let stadiumRef = record[CKGame.stadiumRefKey] as? CKRecord.Reference
|
||||
else { return nil }
|
||||
|
||||
let homeId = homeRef.recordID.recordName
|
||||
let awayId = awayRef.recordID.recordName
|
||||
let stadiumId = stadiumRef.recordID.recordName
|
||||
|
||||
return ckGame.game(homeTeamId: homeId, awayTeamId: awayId, stadiumId: stadiumId)
|
||||
}
|
||||
|
||||
@@ -277,13 +278,11 @@ actor CloudKitService {
|
||||
let stadiumCanonicalId = ckGame.stadiumCanonicalId
|
||||
else { return nil }
|
||||
|
||||
// For the Game domain object, we still need UUIDs - use placeholder
|
||||
// The sync service will use canonical IDs for relationships
|
||||
let placeholderUUID = UUID()
|
||||
// For the Game domain object, use canonical IDs directly
|
||||
guard let game = ckGame.game(
|
||||
homeTeamId: placeholderUUID,
|
||||
awayTeamId: placeholderUUID,
|
||||
stadiumId: placeholderUUID
|
||||
homeTeamId: homeTeamCanonicalId,
|
||||
awayTeamId: awayTeamCanonicalId,
|
||||
stadiumId: stadiumCanonicalId
|
||||
) else { return nil }
|
||||
|
||||
return SyncGame(
|
||||
|
||||
Reference in New Issue
Block a user