添加搜索接口
This commit is contained in:
@@ -12,4 +12,5 @@ export const API_ENDPOINTS = {
|
||||
UPCOMING_MATCHES: "/v1/api/matches/upcoming",
|
||||
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
||||
ODDS: "/v1/api/odds",
|
||||
SEARCH: "/v1/api/search",
|
||||
};
|
||||
|
||||
28
lib/api.ts
28
lib/api.ts
@@ -8,6 +8,7 @@ import {
|
||||
Match,
|
||||
MatchDetailData,
|
||||
OddsData,
|
||||
SearchResult,
|
||||
Sport,
|
||||
UpcomingMatch,
|
||||
} from "@/types/api";
|
||||
@@ -227,3 +228,30 @@ export const fetchOdds = async (
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 搜索联赛、球队或球员
|
||||
export const fetchSearch = async (
|
||||
query: string,
|
||||
sportId?: number
|
||||
): Promise<SearchResult> => {
|
||||
try {
|
||||
const params: { q: string; sportId?: number } = { q: query };
|
||||
if (sportId) {
|
||||
params.sportId = sportId;
|
||||
}
|
||||
|
||||
const response = await apiClient.get<ApiResponse<SearchResult>>(
|
||||
API_ENDPOINTS.SEARCH,
|
||||
{ params }
|
||||
);
|
||||
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Fetch search error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
114
types/api.ts
114
types/api.ts
@@ -287,3 +287,117 @@ export interface OddsData {
|
||||
data: OddsItem[];
|
||||
};
|
||||
}
|
||||
|
||||
// 搜索结果 - 联赛
|
||||
export interface SearchLeague {
|
||||
ID: number;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
DeletedAt: string | null;
|
||||
name: string;
|
||||
countryKey: string;
|
||||
countryName: string;
|
||||
countryLogo: string;
|
||||
sportId: number;
|
||||
logo: string;
|
||||
description: string;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
surface: string;
|
||||
}
|
||||
|
||||
// 搜索结果 - 球员
|
||||
export interface SearchPlayer {
|
||||
ID: number;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
DeletedAt: string | null;
|
||||
name: string;
|
||||
countryKey: string;
|
||||
countryName: string;
|
||||
countryLogo: string;
|
||||
teamKey: string;
|
||||
teamName: string;
|
||||
teamLogo: string;
|
||||
leagueKey: string;
|
||||
leagueName: string;
|
||||
position: string;
|
||||
photo: string;
|
||||
key: string;
|
||||
isActive: boolean;
|
||||
playerNumber: string;
|
||||
playerAge: string;
|
||||
playerMatchPlayed: string;
|
||||
playerGoals: string;
|
||||
playerYellowCards: string;
|
||||
playerRedCards: string;
|
||||
playerMinutes: string;
|
||||
playerInjured: string;
|
||||
playerSubstituteOut: string;
|
||||
playerSubstitutesOnBench: string;
|
||||
playerAssists: string;
|
||||
playerIsCaptain: string;
|
||||
playerShotsTotal: string;
|
||||
playerGoalsConceded: string;
|
||||
playerFoulsCommited: string;
|
||||
playerTackles: string;
|
||||
playerBlocks: string;
|
||||
playerCrossesTotal: string;
|
||||
playerInterceptions: string;
|
||||
playerClearances: string;
|
||||
playerDispossesed: string;
|
||||
playerSaves: string;
|
||||
playerInsideBoxSaves: string;
|
||||
playerDuelsTotal: string;
|
||||
playerDuelsWon: string;
|
||||
playerDribbleAttempts: string;
|
||||
playerDribbleSucc: string;
|
||||
playerPenComm: string;
|
||||
playerPenWon: string;
|
||||
playerPenScored: string;
|
||||
playerPenMissed: string;
|
||||
playerPasses: string;
|
||||
playerPassesAccuracy: string;
|
||||
playerKeyPasses: string;
|
||||
playerRating: string;
|
||||
sportId: number;
|
||||
playerPoints: string;
|
||||
playerRebounds: string;
|
||||
playerSteals: string;
|
||||
playerRank: string;
|
||||
playerTitles: string;
|
||||
playerBday: string;
|
||||
playerRuns: string;
|
||||
playerWickets: string;
|
||||
playerOvers: string;
|
||||
stats: any;
|
||||
tournaments: any;
|
||||
}
|
||||
|
||||
// 搜索结果 - 球队
|
||||
export interface SearchTeam {
|
||||
ID: number;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
DeletedAt: string | null;
|
||||
name: string;
|
||||
countryKey: string;
|
||||
countryName: string;
|
||||
countryLogo: string;
|
||||
leagueKey: string;
|
||||
leagueName: string;
|
||||
leagueLogo: string;
|
||||
logo: string;
|
||||
description: string;
|
||||
founded: number;
|
||||
key: string;
|
||||
isActive: boolean;
|
||||
sportId: number;
|
||||
}
|
||||
|
||||
// 搜索结果
|
||||
export interface SearchResult {
|
||||
leagues: SearchLeague[];
|
||||
players: SearchPlayer[];
|
||||
teams: SearchTeam[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user