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:
@@ -43,7 +43,7 @@ enum NoMatchReason: Sendable {
|
||||
// MARK: - Game Match Result
|
||||
|
||||
struct GameMatchCandidate: Identifiable, Sendable {
|
||||
let id: UUID
|
||||
let id: String
|
||||
let game: Game
|
||||
let stadium: Stadium
|
||||
let homeTeam: Team
|
||||
@@ -67,14 +67,20 @@ struct GameMatchCandidate: Identifiable, Sendable {
|
||||
|
||||
/// Initialize from a scraped historical game
|
||||
init(scrapedGame: ScrapedGame, stadium: Stadium) {
|
||||
self.id = UUID()
|
||||
let matchId = UUID()
|
||||
self.id = "scraped_match_\(matchId.uuidString)"
|
||||
self.stadium = stadium
|
||||
|
||||
// Generate synthetic IDs for scraped games
|
||||
let syntheticHomeTeamId = "scraped_team_\(UUID().uuidString)"
|
||||
let syntheticAwayTeamId = "scraped_team_\(UUID().uuidString)"
|
||||
let syntheticGameId = "scraped_game_\(matchId.uuidString)"
|
||||
|
||||
// Create synthetic Team objects from scraped names
|
||||
// Scraped names already include city (e.g., "Chicago Cubs"), so we use empty city
|
||||
// to avoid duplication in fullName computed property
|
||||
self.homeTeam = Team(
|
||||
id: UUID(),
|
||||
id: syntheticHomeTeamId,
|
||||
name: scrapedGame.homeTeam,
|
||||
abbreviation: String(scrapedGame.homeTeam.suffix(3)).uppercased(),
|
||||
sport: scrapedGame.sport,
|
||||
@@ -83,7 +89,7 @@ struct GameMatchCandidate: Identifiable, Sendable {
|
||||
)
|
||||
|
||||
self.awayTeam = Team(
|
||||
id: UUID(),
|
||||
id: syntheticAwayTeamId,
|
||||
name: scrapedGame.awayTeam,
|
||||
abbreviation: String(scrapedGame.awayTeam.suffix(3)).uppercased(),
|
||||
sport: scrapedGame.sport,
|
||||
@@ -94,7 +100,7 @@ struct GameMatchCandidate: Identifiable, Sendable {
|
||||
// Create synthetic Game object
|
||||
let year = Calendar.current.component(.year, from: scrapedGame.date)
|
||||
self.game = Game(
|
||||
id: self.id,
|
||||
id: syntheticGameId,
|
||||
homeTeamId: self.homeTeam.id,
|
||||
awayTeamId: self.awayTeam.id,
|
||||
stadiumId: stadium.id,
|
||||
|
||||
Reference in New Issue
Block a user