| |
| |
| |
| |
| |
| |
|
|
| const API_BASE = ''; |
|
|
| export interface AptitudeTopic { |
| id: string; |
| chapter_no: number; |
| chapter_name: string; |
| } |
|
|
| export interface AptitudeTopicContent extends AptitudeTopic { |
| content: string; |
| } |
|
|
| |
| |
| |
| export async function fetchAptitudeTopics(category: string): Promise<AptitudeTopic[]> { |
| const res = await fetch(`${API_BASE}/api/aptitude/topics?category=${category}`, { |
| 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: AptitudeTopic[] }; |
| return data.topics ?? []; |
| } |
|
|
| |
| |
| |
| export async function fetchAptitudeTopicContent(category: string, topicNo: number): Promise<AptitudeTopicContent> { |
| const res = await fetch(`${API_BASE}/api/aptitude/topics/${topicNo}?category=${category}`, { |
| method: 'GET', |
| headers: { 'Content-Type': 'application/json' }, |
| }); |
|
|
| if (!res.ok) { |
| throw new Error(`API error ${res.status}: ${res.statusText}`); |
| } |
|
|
| return await res.json() as AptitudeTopicContent; |
| } |
|
|
| export interface ExplainRequest { |
| question: string; |
| options: string; |
| answer: string; |
| topic: string; |
| } |
|
|
| |
| |
| |
| |
| export async function generateAptitudeExplanation(req: ExplainRequest): Promise<string> { |
| const res = await fetch(`${API_BASE}/api/ai/explain`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(req), |
| }); |
|
|
| if (!res.ok) { |
| const err = await res.json().catch(() => ({})) as { error?: string }; |
| throw new Error(err?.error ?? `API error ${res.status}`); |
| } |
|
|
| const data = await res.json() as { explanation: string }; |
| return data.explanation ?? ''; |
| } |
|
|