tracker / app /routes /records.py
MatrixIA's picture
Upload 24 files
fade1d6 verified
from fastapi import APIRouter, Depends, Query
from typing import List, Dict, Any
from ..services.record_service import RecordService
from ..models.monthly_record import MonthlyRecordCreate, MonthlyRecordUpdate
router = APIRouter(prefix="/api/v1", tags=["records"])
def get_service() -> RecordService:
return RecordService()
@router.get("/records/{month_key}")
async def get_record(month_key: str, svc: RecordService = Depends(get_service)) -> Dict[str, Any]:
return await svc.get_by_month_key(month_key)
@router.get("/records")
async def list_records(
limit: int = Query(12, ge=1, le=200),
skip: int = Query(0, ge=0),
svc: RecordService = Depends(get_service),
) -> List[Dict[str, Any]]:
return await svc.list(limit=limit, skip=skip)
@router.post("/records", status_code=201)
async def create_record(payload: MonthlyRecordCreate, svc: RecordService = Depends(get_service)) -> Dict[str, Any]:
return await svc.create(payload)
@router.put("/records/{month_key}")
async def update_record(month_key: str, payload: MonthlyRecordUpdate, svc: RecordService = Depends(get_service)) -> Dict[str, Any]:
return await svc.update(month_key, payload)
@router.delete("/records/{month_key}", status_code=204)
async def delete_record(month_key: str, svc: RecordService = Depends(get_service)) -> None:
await svc.delete(month_key)
# Default categories
DEFAULT_CATEGORIES = [
{"category_id": "housing", "name": "Housing (Rent/Mortgage)", "amount": 0.0, "color": "#4299e1"},
{"category_id": "utilities", "name": "Utilities (Water/Power/Internet)", "amount": 0.0, "color": "#805ad5"},
{"category_id": "groceries", "name": "Food & Groceries", "amount": 0.0, "color": "#48bb78"},
{"category_id": "transport", "name": "Transport (Fuel/Taxi/Transit)", "amount": 0.0, "color": "#ed8936"},
{"category_id": "health", "name": "Healthcare/Pharmacy", "amount": 0.0, "color": "#f56565"},
{"category_id": "education", "name": "Education/Books", "amount": 0.0, "color": "#38b2ac"},
{"category_id": "family", "name": "Family/Children", "amount": 0.0, "color": "#d69e2e"},
{"category_id": "misc", "name": "Miscellaneous", "amount": 0.0, "color": "#a0aec0"},
]
@router.get("/categories/default")
async def default_categories() -> List[dict]:
return DEFAULT_CATEGORIES