File size: 1,293 Bytes
f91a684 3bda374 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 53 54 | /**
* 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<CNTopic[]> {
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<CNTopicContent> {
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;
}
|