supervisor step3
This commit is contained in:
72
supervisor/html/js/ApiClient.js
Normal file
72
supervisor/html/js/ApiClient.js
Normal file
@ -0,0 +1,72 @@
|
||||
// js/ApiClient.js
|
||||
export class ApiClient {
|
||||
constructor({ baseUrl, authToken, csrfToken }) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.authToken = authToken;
|
||||
this.csrfToken = csrfToken;
|
||||
}
|
||||
|
||||
async request(endpoint, options = {}) {
|
||||
const url = `${this.baseUrl}${endpoint}`;
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Token ${this.authToken}`,
|
||||
'X-CSRF-Token': this.csrfToken
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
...headers,
|
||||
...options.headers
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (contentType && contentType.includes("application/json")) {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
return await response.text();
|
||||
} catch (error) {
|
||||
console.error('API request failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// イベント関連のAPI
|
||||
async getEvents() {
|
||||
return this.request('/new-events/');
|
||||
}
|
||||
|
||||
async getZekkenNumbers(eventCode) {
|
||||
return this.request(`/zekken_numbers/${eventCode}`);
|
||||
}
|
||||
|
||||
// チーム関連のAPI
|
||||
async getTeamInfo(zekkenNumber) {
|
||||
return this.request(`/team_info/${zekkenNumber}/`);
|
||||
}
|
||||
|
||||
async getCheckins(zekkenNumber, eventCode) {
|
||||
return this.request(`/checkins/${zekkenNumber}/${eventCode}/`);
|
||||
}
|
||||
|
||||
async updateCheckin(checkinId, data) {
|
||||
return this.request(`/checkins/${checkinId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
}
|
||||
|
||||
async deleteCheckin(checkinId) {
|
||||
return this.request(`/checkins/${checkinId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user