/** * 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 { 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 { 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(); }