paisable icon indicating copy to clipboard operation
paisable copied to clipboard

enhancement: Refactor API calls in frontend into a centralized service layer

Open tanmaygautam11 opened this issue 1 year ago • 2 comments

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

  1. Create frontend/src/api/transactionService.js and move all transaction-related API calls there.
  2. Export functions such as getSummary, getCharts, getExpenseCategories, etc.
  3. 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.

tanmaygautam11 avatar Oct 09 '25 15:10 tanmaygautam11

@archa8 Please assign this issue to me.

tanmaygautam11 avatar Oct 09 '25 15:10 tanmaygautam11

Assigned @tanmaygautam11

archa8 avatar Oct 09 '25 20:10 archa8