实现详情页
This commit is contained in:
29
lib/api.ts
29
lib/api.ts
@@ -1,5 +1,11 @@
|
||||
import { API_CONFIG, API_ENDPOINTS } from "@/constants/api";
|
||||
import { ApiResponse, Match, Sport } from "@/types/api";
|
||||
import {
|
||||
ApiListResponse,
|
||||
ApiResponse,
|
||||
Match,
|
||||
MatchDetailData,
|
||||
Sport,
|
||||
} from "@/types/api";
|
||||
import axios from "axios";
|
||||
|
||||
const apiClient = axios.create({
|
||||
@@ -12,7 +18,7 @@ const apiClient = axios.create({
|
||||
|
||||
export const fetchSports = async (): Promise<Sport[]> => {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<Sport>>(
|
||||
const response = await apiClient.get<ApiResponse<ApiListResponse<Sport>>>(
|
||||
API_ENDPOINTS.SPORTS
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
@@ -28,7 +34,7 @@ export const fetchSports = async (): Promise<Sport[]> => {
|
||||
|
||||
export const fetchTodayMatches = async (sportId: number): Promise<Match[]> => {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<Match>>(
|
||||
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
|
||||
API_ENDPOINTS.MATCHES_TODAY,
|
||||
{
|
||||
params: { sport_id: sportId },
|
||||
@@ -44,3 +50,20 @@ export const fetchTodayMatches = async (sportId: number): Promise<Match[]> => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchMatchDetail = async (
|
||||
id: string
|
||||
): Promise<MatchDetailData> => {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<MatchDetailData>>(
|
||||
API_ENDPOINTS.MATCH_DETAIL(id)
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Fetch match detail error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user