paisable
paisable copied to clipboard
enhancement: Refactor API calls in frontend into a centralized service layer
Current Behavior
Multiple frontend pages such as DashboardPage.jsx and ReceiptsPage.jsx make API calls directly using the imported api instance. These calls are scattered throughout components, which makes it harder to maintain, test, or update API logic in one place.
Suggested Improvement
Refactor transaction-related API calls into a dedicated service module (e.g., frontend/src/api/transactionService.js). Update all relevant pages and components to use this service for transaction-related requests. This improves maintainability and enables easier future changes.
Benefits
- Easier maintenance: All transaction API logic is centralized.
- Improved testability: Service functions can be mocked or tested independently.
- Cleaner components: Components focus on UI and state, not API logic.
Possible Implementation
- Create
frontend/src/api/transactionService.jsand move all transaction-related API calls there. - Export functions such as
getSummary,getCharts,getExpenseCategories, etc. - Update components (e.g., DashboardPage.jsx, ReceiptsPage.jsx, utils/transactions.js) to import and use these functions instead of direct calls to
api.get.
// Example transactionService.js
import api from './axios';
export const getSummary = () => api.get('/transactions/summary');
export const getCharts = () => api.get('/transactions/charts');
export const getExpenseCategories = () => api.get('/transactions/categories/expense');
export const getIncomeCategories = () => api.get('/transactions/categories/income');
export const exportTransactionsCSV = () =>
api.get('/transactions/export', { responseType: 'blob' });
Alternatives Considered
- Leaving API calls as-is; not recommended for maintainability.
- Refactoring only one page at a time.
@archa8 Please assign this issue to me.
Assigned @tanmaygautam11