From ff2031f6ff6f4a7e6d441c9ed2372f004ba34499 Mon Sep 17 00:00:00 2001 From: Biswa Kalyan Bhuyan Date: Fri, 25 Apr 2025 02:19:47 +0530 Subject: finance/backend: feat: added v1/accounts for accounts CRUD --- frontend/src/lib/api.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'frontend/src') diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 35ef8d6..be77f16 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -75,6 +75,40 @@ export const authApi = { } }; +// Account API +export interface Account { + ID: number; + CreatedAt: string; + UpdatedAt: string; + DeletedAt: string | null; + UserID: number; + Name: string; + Type: string; + Balance: number; +} + +export interface AccountInput { + name: string; + type: string; + balance: number; +} + +export const accountApi = { + getAccounts: () => fetchWithAuth('/accounts'), + getAccount: (id: number) => fetchWithAuth(`/accounts/${id}`), + createAccount: (account: AccountInput) => fetchWithAuth('/accounts', { + method: 'POST', + body: JSON.stringify(account) + }), + updateAccount: (id: number, account: Partial) => fetchWithAuth(`/accounts/${id}`, { + method: 'PUT', + body: JSON.stringify(account) + }), + deleteAccount: (id: number) => fetchWithAuth(`/accounts/${id}`, { + method: 'DELETE' + }) +}; + // Loan API export interface Loan { ID: number; -- cgit v1.2.3-59-g8ed1b