diff --git a/constants/api.ts b/constants/api.ts index 8c502a5..39a5198 100644 --- a/constants/api.ts +++ b/constants/api.ts @@ -5,6 +5,7 @@ export const API_CONFIG = { export const API_ENDPOINTS = { SPORTS: "/v1/api/sports", + COUNTRIES: "/v1/api/countries", 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 1de6ea5..903c9be 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -2,6 +2,7 @@ import { API_CONFIG, API_ENDPOINTS } from "@/constants/api"; import { ApiListResponse, ApiResponse, + Country, Match, MatchDetailData, Sport, @@ -32,6 +33,21 @@ export const fetchSports = async (): Promise => { } }; +export const fetchCountries = async (): Promise => { + try { + const response = await apiClient.get>>( + API_ENDPOINTS.COUNTRIES + ); + if (response.data.code === 0) { + return response.data.data.list; + } + throw new Error(response.data.message); + } catch (error) { + console.error("Fetch countries 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 7e40e64..742619e 100644 --- a/types/api.ts +++ b/types/api.ts @@ -30,6 +30,16 @@ export interface ApiListResponse { total: number; } +export interface Country { + id: number; + code: string; + name: string; + flagIcon: string; + createdAt: string; + updatedAt: string; + isActive: boolean; +} + export interface GoalEvent { time: string; home_scorer?: string;