From 91cf23cd11b6779685fa70c6cf68eceec8358db1 Mon Sep 17 00:00:00 2001 From: xianyi Date: Tue, 13 Jan 2026 17:13:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=81=94=E8=B5=9B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constants/api.ts | 1 + lib/api.ts | 25 +++++++++++++++++++++++++ types/api.ts | 15 +++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/constants/api.ts b/constants/api.ts index 39a5198..6509dd5 100644 --- a/constants/api.ts +++ b/constants/api.ts @@ -6,6 +6,7 @@ export const API_CONFIG = { export const API_ENDPOINTS = { SPORTS: "/v1/api/sports", COUNTRIES: "/v1/api/countries", + LEAGUES: "/v1/api/leagues", MATCHES_TODAY: "/v1/api/matches/today", MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`, }; diff --git a/lib/api.ts b/lib/api.ts index 903c9be..2f0d7c7 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -3,6 +3,7 @@ import { ApiListResponse, ApiResponse, Country, + League, Match, MatchDetailData, Sport, @@ -48,6 +49,30 @@ export const fetchCountries = async (): Promise => { } }; +export const fetchLeagues = async ( + sportId: number, + countryKey: string +): Promise => { + try { + const response = await apiClient.get>>( + API_ENDPOINTS.LEAGUES, + { + params: { + sportId, + countryKey, + }, + } + ); + if (response.data.code === 0) { + return response.data.data.list; + } + throw new Error(response.data.message); + } catch (error) { + console.error("Fetch leagues error:", error); + throw error; + } +}; + export const fetchTodayMatches = async (sportId: number): Promise => { try { const response = await apiClient.get>>( diff --git a/types/api.ts b/types/api.ts index 742619e..29007b9 100644 --- a/types/api.ts +++ b/types/api.ts @@ -40,6 +40,21 @@ export interface Country { isActive: boolean; } +export interface League { + id: number; + key: string; + name: string; + description: string; + sportId: number; + countryKey: string; + countryName: string; + countryLogo: string; + logo: string; + isActive: boolean; + createdAt: string; + updatedAt: string; +} + export interface GoalEvent { time: string; home_scorer?: string;