| |
| |
| |
| |
|
|
| class APIClient { |
| constructor() { |
| this.baseURL = ''; |
| } |
|
|
| |
| |
| |
| |
| |
| async fetchChallenges(preferences) { |
| const response = await fetch('/api/topcoder-dry-run', { |
| method: 'POST', |
| headers: { |
| 'Content-Type': 'application/json', |
| }, |
| body: JSON.stringify({ |
| preferences: preferences || '' |
| }) |
| }); |
|
|
| if (!response.ok) { |
| throw new Error(`HTTP error! status: ${response.status}`); |
| } |
|
|
| const data = await response.json(); |
| |
| if (data.error) { |
| throw new Error(data.error); |
| } |
|
|
| return data; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async registerUser(email, preferences) { |
| const response = await fetch('/api/register-user', { |
| method: 'POST', |
| headers: { |
| 'Content-Type': 'application/json', |
| }, |
| body: JSON.stringify({ |
| email: email, |
| preferences: preferences || '' |
| }) |
| }); |
|
|
| if (!response.ok) { |
| const errorData = await response.json(); |
| throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); |
| } |
|
|
| return await response.json(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async updateUserPreferences(email, preferences) { |
| const response = await fetch('/api/update-preferences', { |
| method: 'POST', |
| headers: { |
| 'Content-Type': 'application/json', |
| }, |
| body: JSON.stringify({ |
| email: email, |
| preferences: preferences || '' |
| }) |
| }); |
|
|
| if (!response.ok) { |
| const errorData = await response.json(); |
| throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); |
| } |
|
|
| return await response.json(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async toggleUserActive(email, active) { |
| const response = await fetch('/api/toggle-user', { |
| method: 'POST', |
| headers: { |
| 'Content-Type': 'application/json', |
| }, |
| body: JSON.stringify({ |
| email: email, |
| active: active |
| }) |
| }); |
|
|
| if (!response.ok) { |
| const errorData = await response.json(); |
| throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); |
| } |
|
|
| return await response.json(); |
| } |
|
|
| |
| |
| |
| |
| |
| async getUserByEmail(email) { |
| const response = await fetch(`/api/user/${encodeURIComponent(email)}`); |
| |
| if (!response.ok) { |
| if (response.status === 404) { |
| return null; |
| } |
| const errorData = await response.json(); |
| throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); |
| } |
|
|
| const data = await response.json(); |
| return data.success ? data.user : null; |
| } |
|
|
| |
| |
| |
| |
| async triggerDailyNotifications() { |
| const response = await fetch('/api/trigger-daily-notifications', { |
| method: 'POST', |
| headers: { |
| 'Content-Type': 'application/json', |
| } |
| }); |
|
|
| if (!response.ok) { |
| const errorData = await response.json(); |
| throw new Error(errorData.detail || `HTTP error! status: ${response.status}`); |
| } |
|
|
| return await response.json(); |
| } |
| } |
|
|
| |
| const apiClient = new APIClient(); |
|
|