Add multi-currency to the spending summary

Python · FastAPI · intermediate · modification

Extends the spending-summary endpoint for the new multi-currency billing. Narrows the total from all-time to the current calendar month and reports the period alongside it, so the dashboard can label the figure. Keeps the response model tight.

The billing dashboard's headline number; the same endpoint now serves accounts on USD, EUR, and GBP plans.

Requirements

Files touched

--- app/routes/summary.py
 from pydantic import BaseModel
 from fastapi import APIRouter, HTTPException
-from app.db import get_account, sum_all_charges
+from app.db import get_account, sum_charges_for_month
 
 router = APIRouter()
 class SpendingSummary(BaseModel):
     account_id: int
+    period: str
     total_cents: int
 
         raise HTTPException(status_code=404, detail="account not found")
 
-    total_cents = await sum_all_charges(account_id)
+    today = date.today()
+    period = f"{today.year:04d}-{today.month:02d}"
+    total_cents = await sum_charges_for_month(account_id, today.year, today.month)
 
     return SpendingSummary(
         account_id=account_id,
+        period=period,
         total_cents=total_cents,
     )

Review this PR

Python practice