File size: 1,157 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 | /**
* 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;
}
|