diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/lib/api.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index e654007..11cee62 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -176,6 +176,56 @@ export const transactionApi = { }) }; +// Goal API +export interface Goal { + ID: number; + CreatedAt: string; + UpdatedAt: string; + DeletedAt: string | null; + UserID: number; + Name: string; + TargetAmount: number; + CurrentAmount: number; + TargetDate: string | null; + Status: "Active" | "Achieved" | "Cancelled"; +} + +export interface GoalInput { + name: string; + targetAmount: number; + currentAmount?: number; + targetDate?: string; // YYYY-MM-DD format + status?: "Active" | "Achieved" | "Cancelled"; +} + +export const goalApi = { + getGoals: (status?: "Active" | "Achieved" | "Cancelled") => { + const queryParams = status ? `?status=${status}` : ''; + return fetchWithAuth(`/goals${queryParams}`); + }, + + getGoal: (id: number) => fetchWithAuth(`/goals/${id}`), + + createGoal: (goal: GoalInput) => fetchWithAuth('/goals', { + method: 'POST', + body: JSON.stringify(goal) + }), + + updateGoal: (id: number, goal: Partial<GoalInput>) => fetchWithAuth(`/goals/${id}`, { + method: 'PUT', + body: JSON.stringify(goal) + }), + + updateGoalProgress: (id: number, currentAmount: number) => fetchWithAuth(`/goals/${id}/progress`, { + method: 'PATCH', + body: JSON.stringify({ currentAmount }) + }), + + deleteGoal: (id: number) => fetchWithAuth(`/goals/${id}`, { + method: 'DELETE' + }) +}; + // Loan API export interface Loan { ID: number; |