RYP / src /lib /cProgrammingClient.ts
Soumya79's picture
Upload 1361 files
f91a684 verified
/**
* cProgrammingClient.ts
* ---------------------
* Fetches C Programming topic data from the Go backend.
*/
export interface CSectionPreview {
id: string;
section: string;
section_title: string;
has_content: boolean;
}
export interface CChapterTopic {
id: string;
chapter_no: number;
chapter_name: string;
subtitle: string;
level: string;
section_count: number;
content_count: number;
sections: CSectionPreview[];
}
export interface CSection extends CSectionPreview {
chapter?: number;
chapter_no: number;
chapter_name?: string;
title?: string;
content: string;
[key: string]: any;
}
export interface CChapterContent extends CChapterTopic {
sections: CSection[];
}
export async function fetchCTopics(): Promise<CChapterTopic[]> {
const res = await fetch('/api/c/topics', {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!res.ok) throw new Error(`C topics fetch failed: ${res.status}`);
const data = await res.json();
return data.topics ?? [];
}
export async function fetchCTopicContent(chapterNo: number): Promise<CChapterContent> {
const res = await fetch(`/api/c/topics/${chapterNo}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!res.ok) throw new Error(`C topic content fetch failed: ${res.status}`);
return res.json();
}