Files
service-finder/backend/app/api/v1/endpoints/regions.py

55 lines
1.6 KiB
Python

# /opt/docker/dev/service_finder/backend/app/api/v1/endpoints/regions.py
"""
🌍 Global Region Registry API Endpoint.
Public endpoint that returns the list of active region configurations.
Used by the frontend to drive locale-aware formatting (dates, numbers, currencies)
and financial calculations (VAT, pricing).
Schema: system.region_config
"""
import logging
from typing import List
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from app.api.deps import get_db
from app.models.core_logic import RegionConfig
logger = logging.getLogger(__name__)
router = APIRouter()
@router.get("/regions", response_model=List[dict])
async def list_active_regions(
db: AsyncSession = Depends(get_db),
):
"""
GET /api/v1/system/regions
Returns all active region configurations from the system.region_config table.
This is a public endpoint (no auth required) used by the frontend to:
- Format dates, numbers, and currencies according to locale
- Calculate VAT rates for pricing
- Determine timezone for date displays
"""
stmt = select(RegionConfig).where(RegionConfig.is_active == True).order_by(RegionConfig.country_code)
result = await db.execute(stmt)
regions = result.scalars().all()
return [
{
"country_code": r.country_code,
"name": r.name,
"currency": r.currency,
"default_vat_rate": r.default_vat_rate,
"locale_code": r.locale_code,
"timezone": r.timezone,
"is_active": r.is_active,
}
for r in regions
]