RYP / src /lib /dbmsClient.ts
Soumya79's picture
Upload 1361 files
3bda374 verified
/**
* dbmsClient.ts
* -------------
* Fetches DBMS topic data from the Go backend.
*/
const API_BASE = '';
export interface DBMSTopic {
id: string;
topic_no: number;
topic_name: string;
}
export interface DBMSTopicContent extends DBMSTopic {
content: string;
}
/**
* Fetches all DBMS topics (topic_no and topic_name).
*/
export async function fetchDBMSTopics(): Promise<DBMSTopic[]> {
const res = await fetch(`${API_BASE}/api/dbms/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: DBMSTopic[] };
return data.topics ?? [];
}
/**
* Fetches full content for a specific DBMS topic.
*/
export async function fetchDBMSTopicContent(topicNo: number): Promise<DBMSTopicContent> {
const res = await fetch(`${API_BASE}/api/dbms/topics/${topicNo}`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!res.ok) {
throw new Error(`API error ${res.status}: ${res.statusText}`);
}
return await res.json() as DBMSTopicContent;
}