From b3ad386d2bec18974fc85e748b684df7ed7210c9 Mon Sep 17 00:00:00 2001 From: Trey t Date: Mon, 12 Jan 2026 10:51:26 -0600 Subject: [PATCH] refactor: rename fetch methods to filter, add allGames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fetchGames → filterGames (clarifies local SwiftData query) - fetchRichGames → filterRichGames - Add allGames(for:) method for unfiltered game access Co-Authored-By: Claude Opus 4.5 --- SportsTime/Core/Services/DataProvider.swift | 33 +++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/SportsTime/Core/Services/DataProvider.swift b/SportsTime/Core/Services/DataProvider.swift index c60ca37..504526f 100644 --- a/SportsTime/Core/Services/DataProvider.swift +++ b/SportsTime/Core/Services/DataProvider.swift @@ -118,8 +118,8 @@ final class AppDataProvider: ObservableObject { // MARK: - Game Fetching - /// Fetch games from SwiftData within date range - func fetchGames(sports: Set, startDate: Date, endDate: Date) async throws -> [Game] { + /// Filter games from SwiftData within date range + func filterGames(sports: Set, 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) async throws -> [Game] { + guard let context = modelContext else { + throw DataProviderError.contextNotConfigured + } + + let sportStrings = sports.map { $0.rawValue } + + let descriptor = FetchDescriptor( + predicate: #Predicate { 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, 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, 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],