添加国家列表接口
This commit is contained in:
@@ -5,6 +5,7 @@ export const API_CONFIG = {
|
|||||||
|
|
||||||
export const API_ENDPOINTS = {
|
export const API_ENDPOINTS = {
|
||||||
SPORTS: "/v1/api/sports",
|
SPORTS: "/v1/api/sports",
|
||||||
|
COUNTRIES: "/v1/api/countries",
|
||||||
MATCHES_TODAY: "/v1/api/matches/today",
|
MATCHES_TODAY: "/v1/api/matches/today",
|
||||||
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
16
lib/api.ts
16
lib/api.ts
@@ -2,6 +2,7 @@ import { API_CONFIG, API_ENDPOINTS } from "@/constants/api";
|
|||||||
import {
|
import {
|
||||||
ApiListResponse,
|
ApiListResponse,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
|
Country,
|
||||||
Match,
|
Match,
|
||||||
MatchDetailData,
|
MatchDetailData,
|
||||||
Sport,
|
Sport,
|
||||||
@@ -32,6 +33,21 @@ export const fetchSports = async (): Promise<Sport[]> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchCountries = async (): Promise<Country[]> => {
|
||||||
|
try {
|
||||||
|
const response = await apiClient.get<ApiResponse<ApiListResponse<Country>>>(
|
||||||
|
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<Match[]> => {
|
export const fetchTodayMatches = async (sportId: number): Promise<Match[]> => {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
|
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
|
||||||
|
|||||||
10
types/api.ts
10
types/api.ts
@@ -30,6 +30,16 @@ export interface ApiListResponse<T> {
|
|||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Country {
|
||||||
|
id: number;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
flagIcon: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GoalEvent {
|
export interface GoalEvent {
|
||||||
time: string;
|
time: string;
|
||||||
home_scorer?: string;
|
home_scorer?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user