From 57b913d135e68188b31ddf3ae84748663f921338 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:04:42 +0000 Subject: [PATCH] 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. --- be/app/api/v1/api.py | 2 +- fe/src/config/api-config.ts | 20 ++++++++++---------- fe/src/services/expenseService.ts | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/be/app/api/v1/api.py b/be/app/api/v1/api.py index 587a1b8..adc28cc 100644 --- a/be/app/api/v1/api.py +++ b/be/app/api/v1/api.py @@ -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"]) \ No newline at end of file diff --git a/fe/src/config/api-config.ts b/fe/src/config/api-config.ts index 052aade..cc12da9 100644 --- a/fe/src/config/api-config.ts +++ b/fe/src/config/api-config.ts @@ -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 diff --git a/fe/src/services/expenseService.ts b/fe/src/services/expenseService.ts index 7893575..f118d88 100644 --- a/fe/src/services/expenseService.ts +++ b/fe/src/services/expenseService.ts @@ -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 { export const expenseService = { async createExpense(data: CreateExpenseData): Promise { - const response = await api.post('/expenses', data) + const response = await api.post(API_ENDPOINTS.FINANCIALS.EXPENSES, data) return response.data }, async updateExpense(id: number, data: UpdateExpenseData): Promise { - const response = await api.put(`/expenses/${id}`, data) + const response = await api.put(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString()), data) return response.data }, async deleteExpense(id: number): Promise { - await api.delete(`/expenses/${id}`) + await api.delete(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString())) }, async getExpense(id: number): Promise { - const response = await api.get(`/expenses/${id}`) + const response = await api.get(API_ENDPOINTS.FINANCIALS.EXPENSE(id.toString())) return response.data }, @@ -55,7 +55,7 @@ export const expenseService = { group_id?: number isRecurring?: boolean }): Promise { - const response = await api.get('/expenses', { params }) + const response = await api.get(API_ENDPOINTS.FINANCIALS.EXPENSES, { params }) return response.data },