添加收藏
This commit is contained in:
82
lib/api.ts
82
lib/api.ts
@@ -5,6 +5,8 @@ import {
|
||||
AppleSignInRequest,
|
||||
AppleSignInResponse,
|
||||
Country,
|
||||
FavoriteCheckResponse,
|
||||
FavoriteRequest,
|
||||
H2HData,
|
||||
League,
|
||||
LiveScoreMatch,
|
||||
@@ -41,9 +43,10 @@ const refreshTokenApi = async (
|
||||
request: RefreshTokenRequest
|
||||
): Promise<RefreshTokenResponse> => {
|
||||
try {
|
||||
const response = await apiClient.post<
|
||||
ApiResponse<RefreshTokenResponse>
|
||||
>(API_ENDPOINTS.REFRESH_TOKEN, request);
|
||||
const response = await apiClient.post<ApiResponse<RefreshTokenResponse>>(
|
||||
API_ENDPOINTS.REFRESH_TOKEN,
|
||||
request
|
||||
);
|
||||
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
@@ -65,7 +68,9 @@ apiClient.interceptors.response.use(
|
||||
try {
|
||||
const refreshTokenValue = await storage.getRefreshToken();
|
||||
if (refreshTokenValue) {
|
||||
const res = await refreshTokenApi({ refreshToken: refreshTokenValue });
|
||||
const res = await refreshTokenApi({
|
||||
refreshToken: refreshTokenValue,
|
||||
});
|
||||
await storage.setAccessToken(res.accessToken);
|
||||
originalRequest.headers.Authorization = `Bearer ${res.accessToken}`;
|
||||
return apiClient(originalRequest);
|
||||
@@ -203,9 +208,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;
|
||||
@@ -371,9 +376,10 @@ export const appleSignIn = async (
|
||||
request: AppleSignInRequest
|
||||
): Promise<AppleSignInResponse> => {
|
||||
try {
|
||||
const response = await apiClient.post<
|
||||
ApiResponse<AppleSignInResponse>
|
||||
>(API_ENDPOINTS.APPLE_SIGNIN, request);
|
||||
const response = await apiClient.post<ApiResponse<AppleSignInResponse>>(
|
||||
API_ENDPOINTS.APPLE_SIGNIN,
|
||||
request
|
||||
);
|
||||
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
@@ -421,3 +427,59 @@ export const fetchUserProfile = async (): Promise<UserProfile> => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const addFavorite = async (request: FavoriteRequest): Promise<any> => {
|
||||
try {
|
||||
const response = await apiClient.post<ApiResponse<any>>(
|
||||
API_ENDPOINTS.FAVORITES,
|
||||
request
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Add favorite error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const removeFavorite = async (request: {
|
||||
type: string;
|
||||
typeId: string;
|
||||
}): Promise<any> => {
|
||||
try {
|
||||
const response = await apiClient.delete<ApiResponse<any>>(
|
||||
API_ENDPOINTS.FAVORITES,
|
||||
{ data: request }
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Remove favorite error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const checkFavorite = async (
|
||||
type: string,
|
||||
typeId: string
|
||||
): Promise<FavoriteCheckResponse> => {
|
||||
try {
|
||||
const response = await apiClient.get<ApiResponse<FavoriteCheckResponse>>(
|
||||
API_ENDPOINTS.CHECK_FAVORITE,
|
||||
{
|
||||
params: { type, typeId },
|
||||
}
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
return response.data.data;
|
||||
}
|
||||
throw new Error(response.data.message);
|
||||
} catch (error) {
|
||||
console.error("Check favorite error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user