File size: 1,167 Bytes
9205fca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:8000';

export const api = {
  chat: async (message: string, topic?: string) => {
    const response = await fetch(`${API_BASE_URL}/api/chat`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ message, topic }),
    });
    return response.json();
  },

  executeCode: async (code: string) => {
    const response = await fetch(`${API_BASE_URL}/api/execute-code`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ code }),
    });
    return response.json();
  },

  getLearningPaths: async () => {
    const response = await fetch(`${API_BASE_URL}/api/learning-paths`);
    return response.json();
  },

  updateProgress: async (userId: string, moduleId: string) => {
    const response = await fetch(`${API_BASE_URL}/api/update-progress`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ userId, moduleId }),
    });
    return response.json();
  },
};

export default api;