From 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期二, 30 九月 2025 17:38:04 +0800 Subject: [PATCH] feat: 完善比赛晋级功能并清理测试文件 --- web/src/api/activity.js | 103 ++++++++++++++------------------------------------- 1 files changed, 28 insertions(+), 75 deletions(-) diff --git a/web/src/api/activity.js b/web/src/api/activity.js index 9039862..6ea223a 100644 --- a/web/src/api/activity.js +++ b/web/src/api/activity.js @@ -1,6 +1,6 @@ // 姣旇禌绠$悊 API -const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql'; +import { API_CONFIG, graphqlRequest } from '@/config/api'; // GraphQL 鏌ヨ璇彞 const GET_ACTIVITIES_QUERY = ` @@ -61,6 +61,7 @@ playerMax state stateName + sortOrder ratingScheme { id name @@ -85,6 +86,7 @@ name state stateName + sortOrder parent { id name @@ -118,95 +120,46 @@ // API 鍑芥暟 export const getActivities = async (page = 0, size = 10, name = '') => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ACTIVITIES_QUERY, - variables: { page, size, name } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(GET_ACTIVITIES_QUERY, { page, size, name }); + return data.activities; + } catch (error) { + throw new Error(error.message || '鑾峰彇姣旇禌鍒楄〃澶辫触'); } - return result.data.activities; }; export const getActivity = async (id) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ACTIVITY_QUERY, - variables: { id } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(GET_ACTIVITY_QUERY, { id }); + return data.activity; + } catch (error) { + throw new Error(error.message || '鑾峰彇姣旇禌璇︽儏澶辫触'); } - return result.data.activity; }; export const getAllActivities = async () => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ALL_ACTIVITIES_QUERY - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(GET_ALL_ACTIVITIES_QUERY); + return data.allActivities; + } catch (error) { + throw new Error(error.message || '鑾峰彇鎵�鏈夋瘮璧涘け璐�'); } - return result.data.allActivities; }; export const saveActivity = async (activityData) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: SAVE_ACTIVITY_MUTATION, - variables: { input: activityData } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(SAVE_ACTIVITY_MUTATION, { input: activityData }); + return data.saveActivity; + } catch (error) { + throw new Error(error.message || '淇濆瓨姣旇禌澶辫触'); } - return result.data.saveActivity; }; export const deleteActivity = async (id) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: DELETE_ACTIVITY_MUTATION, - variables: { id } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(DELETE_ACTIVITY_MUTATION, { id }); + return data.deleteActivity; + } catch (error) { + throw new Error(error.message || '鍒犻櫎姣旇禌澶辫触'); } - return result.data.deleteActivity; }; \ No newline at end of file -- Gitblit v1.8.0