From d8856efd30dfcb05b26a5b66b5bb14cc0604e2b1 Mon Sep 17 00:00:00 2001 From: Biswa Kalyan Bhuyan Date: Fri, 25 Apr 2025 02:39:12 +0530 Subject: finance/backend: feat: added v1/goals and handlers/goal_handler for Goal CRUD --- frontend/src/lib/api.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'frontend') 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) => 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; -- cgit v1.2.3-59-g8ed1b