/** * cnClient.ts * ------------- * Fetches Computer Networks topic data from the Go backend. */ const API_BASE = ''; export interface CNTopic { id: string; chapter_no: number; chapter_name: string; subtitle: string; level: string; topics: string[]; } export interface CNTopicContent extends CNTopic { content: any; // Using any to match the dynamic bson.M structure } /** * Fetches all Computer Networks topics (chapter_no, chapter_name, etc). */ export async function fetchCNTopics(): Promise { const res = await fetch(`${API_BASE}/api/cn/topics`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }); if (!res.ok) { throw new Error(`API error ${res.status}: ${res.statusText}`); } const data = await res.json() as { topics: CNTopic[] }; return data.topics ?? []; } /** * Fetches full content for a specific Computer Networks chapter. */ export async function fetchCNTopicContent(chapterNo: number): Promise { const res = await fetch(`${API_BASE}/api/cn/topics/${chapterNo}`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }); if (!res.ok) { throw new Error(`API error ${res.status}: ${res.statusText}`); } return await res.json() as CNTopicContent; }