Spaces:
Build error
Build error
Create services/api.ts
Browse files- frontend/src/services/api.ts +43 -0
frontend/src/services/api.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:8000';
|
| 2 |
+
|
| 3 |
+
export const api = {
|
| 4 |
+
chat: async (message: string, topic?: string) => {
|
| 5 |
+
const response = await fetch(`${API_BASE_URL}/api/chat`, {
|
| 6 |
+
method: 'POST',
|
| 7 |
+
headers: {
|
| 8 |
+
'Content-Type': 'application/json',
|
| 9 |
+
},
|
| 10 |
+
body: JSON.stringify({ message, topic }),
|
| 11 |
+
});
|
| 12 |
+
return response.json();
|
| 13 |
+
},
|
| 14 |
+
|
| 15 |
+
executeCode: async (code: string) => {
|
| 16 |
+
const response = await fetch(`${API_BASE_URL}/api/execute-code`, {
|
| 17 |
+
method: 'POST',
|
| 18 |
+
headers: {
|
| 19 |
+
'Content-Type': 'application/json',
|
| 20 |
+
},
|
| 21 |
+
body: JSON.stringify({ code }),
|
| 22 |
+
});
|
| 23 |
+
return response.json();
|
| 24 |
+
},
|
| 25 |
+
|
| 26 |
+
getLearningPaths: async () => {
|
| 27 |
+
const response = await fetch(`${API_BASE_URL}/api/learning-paths`);
|
| 28 |
+
return response.json();
|
| 29 |
+
},
|
| 30 |
+
|
| 31 |
+
updateProgress: async (userId: string, moduleId: string) => {
|
| 32 |
+
const response = await fetch(`${API_BASE_URL}/api/update-progress`, {
|
| 33 |
+
method: 'POST',
|
| 34 |
+
headers: {
|
| 35 |
+
'Content-Type': 'application/json',
|
| 36 |
+
},
|
| 37 |
+
body: JSON.stringify({ userId, moduleId }),
|
| 38 |
+
});
|
| 39 |
+
return response.json();
|
| 40 |
+
},
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
export default api;
|