| |
| |
| |
| |
| |
|
|
| export interface JavaSectionPreview { |
| id: string; |
| section: string; |
| section_title: string; |
| has_content: boolean; |
| } |
|
|
| export interface JavaChapterTopic { |
| id: string; |
| chapter_no: number; |
| chapter_name: string; |
| subtitle: string; |
| level: string; |
| section_count: number; |
| content_count: number; |
| sections: JavaSectionPreview[]; |
| } |
|
|
| export interface JavaSection extends JavaSectionPreview { |
| chapter?: number; |
| chapter_no: number; |
| chapter_name?: string; |
| title?: string; |
| content: string; |
| [key: string]: any; |
| } |
|
|
| export interface JavaChapterContent extends JavaChapterTopic { |
| sections: JavaSection[]; |
| } |
|
|
| export async function fetchJavaTopics(): Promise<JavaChapterTopic[]> { |
| const res = await fetch('/api/java/topics', { |
| method: 'GET', |
| headers: { 'Content-Type': 'application/json' }, |
| }); |
| if (!res.ok) throw new Error(`Java topics fetch failed: ${res.status}`); |
| const data = await res.json(); |
| return data.topics ?? []; |
| } |
|
|
| export async function fetchJavaTopicContent(chapterNo: number): Promise<JavaChapterContent> { |
| const res = await fetch(`/api/java/topics/${chapterNo}`, { |
| method: 'GET', |
| headers: { 'Content-Type': 'application/json' }, |
| }); |
| if (!res.ok) throw new Error(`Java topic content fetch failed: ${res.status}`); |
| return res.json(); |
| } |
|
|