Fix: Correct API endpoint pathing for expenses to resolve 404 errors

The expenses frontend was encountering 404 errors due to mismatched API paths
between the frontend calls and backend routing.

This commit addresses the issue by:

1. Modifying backend API routing in `be/app/api/v1/api.py`:
   - Added a `/financials` prefix to the `financials.router`. Expense endpoints are now served under `/api/v1/financials/expenses`.

2. Updating frontend API configuration in `fe/src/config/api-config.ts`:
   - Prepended `/api/v1` to all paths within the `API_ENDPOINTS.FINANCIALS` object to match the new backend structure (e.g., `API_ENDPOINTS.FINANCIALS.EXPENSES` is now `/api/v1/financials/expenses`).

3. Updating frontend expense service in `fe/src/services/expenseService.ts`:
   - Replaced hardcoded relative URLs with the updated constants from `API_ENDPOINTS.FINANCIALS`.
   - Ensured `API_ENDPOINTS` is correctly imported.

These changes align the frontend API calls with the backend endpoint definitions,
resolving the 404 errors.
This commit is contained in:
google-labs-jules[bot] 2025-06-03 10:04:42 +00:00
parent d623c4b27c
commit 57b913d135
3 changed files with 17 additions and 17 deletions

View File

@ -19,7 +19,7 @@ api_router_v1.include_router(lists.router, prefix="/lists", tags=["Lists"])
api_router_v1.include_router(items.router, tags=["Items"])
api_router_v1.include_router(ocr.router, prefix="/ocr", tags=["OCR"])
api_router_v1.include_router(costs.router, prefix="/costs", tags=["Costs"])
api_router_v1.include_router(financials.router)
api_router_v1.include_router(financials.router, prefix="/financials", tags=["Financials"])
api_router_v1.include_router(chores.router, prefix="/chores", tags=["Chores"])
# Add other v1 endpoint routers here later
# e.g., api_router_v1.include_router(users.router, prefix="/users", tags=["Users"])

View File

@ -97,16 +97,16 @@ export const API_ENDPOINTS = {
// Financials
FINANCIALS: {
EXPENSES: '/financials/expenses',
EXPENSE: (id: string) => `/financials/expenses/${id}`,
SETTLEMENTS: '/financials/settlements',
SETTLEMENT: (id: string) => `/financials/settlements/${id}`,
BALANCES: '/financials/balances',
BALANCE: (userId: string) => `/financials/balances/${userId}`,
REPORTS: '/financials/reports',
REPORT: (id: string) => `/financials/reports/${id}`,
CATEGORIES: '/financials/categories',
CATEGORY: (id: string) => `/financials/categories/${id}`,
EXPENSES: '/api/v1/financials/expenses',
EXPENSE: (id: string) => `/api/v1/financials/expenses/${id}`,
SETTLEMENTS: '/api/v1/financials/settlements',
SETTLEMENT: (id: string) => `/api/v1/financials/settlements/${id}`,
BALANCES: '/api/v1/financials/balances',
BALANCE: (userId: string) => `/api/v1/financials/balances/${userId}`,
REPORTS: '/api/v1/financials/reports',
REPORT: (id: string) => `/api/v1/financials/reports/${id}`,
CATEGORIES: '/api/v1/financials/categories',
CATEGORY: (id: string) => `/api/v1/financials/categories/${id}`,
},
// Health

View File

@ -1,5 +1,5 @@
import type { Expense, RecurrencePattern } from '@/types/expense'
import { api } from '@/services/api'
import { api, API_ENDPOINTS } from '@/services/api'
export interface CreateExpenseData {
description: string
@ -32,21 +32,21 @@ export interface UpdateExpenseData extends Partial<CreateExpenseData> {
export const expenseService = {
async createExpense(data: CreateExpenseData): Promise<Expense> {
const response = await api.post<Expense>('/expenses', data)
const response = await api.post<Expense>(API_ENDPOINTS.FINANCIALS.EXPENSES, data)
return response.data
},
async updateExpense(id: number, data: UpdateExpenseData): Promise<Expense> {
const response = await api.put<Expense>(`/expenses/${id}`, data)
const response = await api.put<Expense>(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString()), data)
return response.data
},
async deleteExpense(id: number): Promise<void> {
await api.delete(`/expenses/${id}`)
await api.delete(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString()))
},
async getExpense(id: number): Promise<Expense> {
const response = await api.get<Expense>(`/expenses/${id}`)
const response = await api.get<Expense>(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString()))
return response.data
},
@ -55,7 +55,7 @@ export const expenseService = {
group_id?: number
isRecurring?: boolean
}): Promise<Expense[]> {
const response = await api.get<Expense[]>('/expenses', { params })
const response = await api.get<Expense[]>(API_ENDPOINTS.FINANCIALS.EXPENSES, { params })
return response.data
},