添加搜索接口
This commit is contained in:
34
lib/api.ts
34
lib/api.ts
@@ -8,6 +8,7 @@ import {
|
||||
Match,
|
||||
MatchDetailData,
|
||||
OddsData,
|
||||
SearchResult,
|
||||
Sport,
|
||||
UpcomingMatch,
|
||||
} from "@/types/api";
|
||||
@@ -146,9 +147,9 @@ export const fetchLiveScore = async (
|
||||
): Promise<LiveScoreMatch[]> => {
|
||||
try {
|
||||
const params: { sport_id: number; league_id?: number; timezone?: string } =
|
||||
{
|
||||
sport_id: sportId,
|
||||
};
|
||||
{
|
||||
sport_id: sportId,
|
||||
};
|
||||
|
||||
if (leagueId) {
|
||||
params.league_id = leagueId;
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user