refactor: rename fetch methods to filter, add allGames
- fetchGames → filterGames (clarifies local SwiftData query) - fetchRichGames → filterRichGames - Add allGames(for:) method for unfiltered game access Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -118,8 +118,8 @@ final class AppDataProvider: ObservableObject {
|
||||
|
||||
// MARK: - Game Fetching
|
||||
|
||||
/// Fetch games from SwiftData within date range
|
||||
func fetchGames(sports: Set<Sport>, startDate: Date, endDate: Date) async throws -> [Game] {
|
||||
/// Filter games from SwiftData within date range
|
||||
func filterGames(sports: Set<Sport>, startDate: Date, endDate: Date) async throws -> [Game] {
|
||||
guard let context = modelContext else {
|
||||
throw DataProviderError.contextNotConfigured
|
||||
}
|
||||
@@ -143,6 +143,29 @@ final class AppDataProvider: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all games for specified sports (no date filtering)
|
||||
func allGames(for sports: Set<Sport>) async throws -> [Game] {
|
||||
guard let context = modelContext else {
|
||||
throw DataProviderError.contextNotConfigured
|
||||
}
|
||||
|
||||
let sportStrings = sports.map { $0.rawValue }
|
||||
|
||||
let descriptor = FetchDescriptor<CanonicalGame>(
|
||||
predicate: #Predicate<CanonicalGame> { game in
|
||||
game.deprecatedAt == nil
|
||||
},
|
||||
sortBy: [SortDescriptor(\.dateTime)]
|
||||
)
|
||||
|
||||
let canonicalGames = try context.fetch(descriptor)
|
||||
|
||||
return canonicalGames.compactMap { canonical -> Game? in
|
||||
guard sportStrings.contains(canonical.sport) else { return nil }
|
||||
return canonical.toDomain()
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch a single game by canonical ID
|
||||
func fetchGame(by id: String) async throws -> Game? {
|
||||
guard let context = modelContext else {
|
||||
@@ -160,9 +183,9 @@ final class AppDataProvider: ObservableObject {
|
||||
return canonical.toDomain()
|
||||
}
|
||||
|
||||
/// Fetch games with full team and stadium data
|
||||
func fetchRichGames(sports: Set<Sport>, startDate: Date, endDate: Date) async throws -> [RichGame] {
|
||||
let games = try await fetchGames(sports: sports, startDate: startDate, endDate: endDate)
|
||||
/// Filter games with full team and stadium data within date range
|
||||
func filterRichGames(sports: Set<Sport>, startDate: Date, endDate: Date) async throws -> [RichGame] {
|
||||
let games = try await filterGames(sports: sports, startDate: startDate, endDate: endDate)
|
||||
|
||||
return games.compactMap { game in
|
||||
guard let homeTeam = teamsById[game.homeTeamId],
|
||||
|
||||
Reference in New Issue
Block a user