aboutsummaryrefslogtreecommitdiffstats
path: root/frontend
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswa Kalyan Bhuyan <biswa@surgot.in> 2025-04-25 02:39:12 +0530
committerLibravatarLibravatar Biswa Kalyan Bhuyan <biswa@surgot.in> 2025-04-25 02:39:12 +0530
commitd8856efd30dfcb05b26a5b66b5bb14cc0604e2b1 (patch)
tree6d4c1b99ec45636bf0038a46d90b585302a3a89a /frontend
parent5b23b22c60027f18dfb218789eea0e1e6dc38a37 (diff)
downloadfinance-d8856efd30dfcb05b26a5b66b5bb14cc0604e2b1.tar.gz
finance-d8856efd30dfcb05b26a5b66b5bb14cc0604e2b1.tar.bz2
finance-d8856efd30dfcb05b26a5b66b5bb14cc0604e2b1.zip
finance/backend: feat: added v1/goals and handlers/goal_handler for Goal CRUD
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/lib/api.ts50
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;