添加交锋往绩接口
This commit is contained in:
@@ -13,4 +13,5 @@ export const API_ENDPOINTS = {
|
|||||||
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
||||||
ODDS: "/v1/api/odds",
|
ODDS: "/v1/api/odds",
|
||||||
SEARCH: "/v1/api/search",
|
SEARCH: "/v1/api/search",
|
||||||
|
H2H: "/v1/api/h2h",
|
||||||
};
|
};
|
||||||
|
|||||||
56
lib/api.ts
56
lib/api.ts
@@ -3,6 +3,7 @@ import {
|
|||||||
ApiListResponse,
|
ApiListResponse,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
Country,
|
Country,
|
||||||
|
H2HData,
|
||||||
League,
|
League,
|
||||||
LiveScoreMatch,
|
LiveScoreMatch,
|
||||||
Match,
|
Match,
|
||||||
@@ -255,3 +256,58 @@ export const fetchSearch = async (
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取两队/两球员之间的历史对战数据
|
||||||
|
export const fetchH2H = async (
|
||||||
|
sportId: number,
|
||||||
|
options: {
|
||||||
|
firstTeamId?: number;
|
||||||
|
secondTeamId?: number;
|
||||||
|
firstPlayerId?: number;
|
||||||
|
secondPlayerId?: number;
|
||||||
|
timezone?: string;
|
||||||
|
}
|
||||||
|
): Promise<H2HData> => {
|
||||||
|
try {
|
||||||
|
const params: {
|
||||||
|
sport_id: number;
|
||||||
|
first_team_id?: number;
|
||||||
|
second_team_id?: number;
|
||||||
|
first_player_id?: number;
|
||||||
|
second_player_id?: number;
|
||||||
|
timezone?: string;
|
||||||
|
} = {
|
||||||
|
sport_id: sportId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (options.firstTeamId) {
|
||||||
|
params.first_team_id = options.firstTeamId;
|
||||||
|
}
|
||||||
|
if (options.secondTeamId) {
|
||||||
|
params.second_team_id = options.secondTeamId;
|
||||||
|
}
|
||||||
|
if (options.firstPlayerId) {
|
||||||
|
params.first_player_id = options.firstPlayerId;
|
||||||
|
}
|
||||||
|
if (options.secondPlayerId) {
|
||||||
|
params.second_player_id = options.secondPlayerId;
|
||||||
|
}
|
||||||
|
if (options.timezone) {
|
||||||
|
params.timezone = options.timezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await apiClient.get<ApiResponse<H2HData>>(
|
||||||
|
API_ENDPOINTS.H2H,
|
||||||
|
{ params }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.data.code === 0) {
|
||||||
|
return response.data.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(response.data.message);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Fetch H2H error:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
28
types/api.ts
28
types/api.ts
@@ -401,3 +401,31 @@ export interface SearchResult {
|
|||||||
players: SearchPlayer[];
|
players: SearchPlayer[];
|
||||||
teams: SearchTeam[];
|
teams: SearchTeam[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// H2H 历史对战比赛项
|
||||||
|
export interface H2HMatch {
|
||||||
|
awayTeamKey: string;
|
||||||
|
countryName: string;
|
||||||
|
eventAwayTeam: string;
|
||||||
|
eventCountryKey: string;
|
||||||
|
eventDate: string;
|
||||||
|
eventFinalResult: string;
|
||||||
|
eventHalftimeResult: string;
|
||||||
|
eventHomeTeam: string;
|
||||||
|
eventKey: string;
|
||||||
|
eventLive: string;
|
||||||
|
eventStatus: string;
|
||||||
|
eventTime: string;
|
||||||
|
homeTeamKey: string;
|
||||||
|
leagueKey: string;
|
||||||
|
leagueName: string;
|
||||||
|
leagueRound: string;
|
||||||
|
leagueSeason: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// H2H 历史对战数据
|
||||||
|
export interface H2HData {
|
||||||
|
H2H: H2HMatch[];
|
||||||
|
firstTeamResults: H2HMatch[];
|
||||||
|
secondTeamResults: H2HMatch[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user