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(items.router, tags=["Items"])
api_router_v1.include_router(ocr.router, prefix="/ocr", tags=["OCR"]) 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(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"]) api_router_v1.include_router(chores.router, prefix="/chores", tags=["Chores"])
# Add other v1 endpoint routers here later # Add other v1 endpoint routers here later
# e.g., api_router_v1.include_router(users.router, prefix="/users", tags=["Users"]) # 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
FINANCIALS: { FINANCIALS: {
EXPENSES: '/financials/expenses', EXPENSES: '/api/v1/financials/expenses',
EXPENSE: (id: string) => `/financials/expenses/${id}`, EXPENSE: (id: string) => `/api/v1/financials/expenses/${id}`,
SETTLEMENTS: '/financials/settlements', SETTLEMENTS: '/api/v1/financials/settlements',
SETTLEMENT: (id: string) => `/financials/settlements/${id}`, SETTLEMENT: (id: string) => `/api/v1/financials/settlements/${id}`,
BALANCES: '/financials/balances', BALANCES: '/api/v1/financials/balances',
BALANCE: (userId: string) => `/financials/balances/${userId}`, BALANCE: (userId: string) => `/api/v1/financials/balances/${userId}`,
REPORTS: '/financials/reports', REPORTS: '/api/v1/financials/reports',
REPORT: (id: string) => `/financials/reports/${id}`, REPORT: (id: string) => `/api/v1/financials/reports/${id}`,
CATEGORIES: '/financials/categories', CATEGORIES: '/api/v1/financials/categories',
CATEGORY: (id: string) => `/financials/categories/${id}`, CATEGORY: (id: string) => `/api/v1/financials/categories/${id}`,
}, },
// Health // Health

View File

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