File size: 1,402 Bytes
f91a684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
/**
 * pythonClient.ts
 * -----------
 * Fetches Python Programming topic data from the Go backend.
 */

export interface PythonTopic {
  id: string;
  chapter_no: number;
  chapter_name: string;
  subtitle: string;
  level: string;
  section?: string; // "Course Overview", "Quick Reference", "Learning Path" for non-module docs
}

export interface PythonSection {
  title: string;
  content?: string;
  code?: string[];
  section_number?: string;
  // Some sections have extra fields like string_methods, python_version, etc.
  [key: string]: any;
}

export interface PythonTopicContent {
  id: string;
  chapter_no: number;
  chapter_name: string;
  subtitle?: string;
  level: string;
  sections: PythonSection[];
}

export async function fetchPythonTopics(): Promise<PythonTopic[]> {
  const res = await fetch('/api/python/topics', {
    method: 'GET',
    headers: { 'Content-Type': 'application/json' },
  });
  if (!res.ok) throw new Error(`Python topics fetch failed: ${res.status}`);
  const data = await res.json();
  return data.topics ?? [];
}

export async function fetchPythonTopicContent(chapterNo: number): Promise<PythonTopicContent> {
  const res = await fetch(`/api/python/topics/${chapterNo}`, {
    method: 'GET',
    headers: { 'Content-Type': 'application/json' },
  });
  if (!res.ok) throw new Error(`Python topic content fetch failed: ${res.status}`);
  return res.json();
}