Add GET /api/exchange/price endpoint: - Available to regular users (BOOK_APPOINTMENT permission) - Returns current BTC/EUR price with admin premium applied - Uses cached price from PriceHistory if not stale - Fetches fresh price from Bitfinex if needed - Returns is_stale flag when price is older than 5 minutes - Includes exchange configuration (min/max EUR, increment) - Handles fetch failures gracefully (returns stale price with error)
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""FastAPI application entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from database import Base, engine
|
|
from routes import audit as audit_routes
|
|
from routes import auth as auth_routes
|
|
from routes import availability as availability_routes
|
|
from routes import booking as booking_routes
|
|
from routes import exchange as exchange_routes
|
|
from routes import invites as invites_routes
|
|
from routes import meta as meta_routes
|
|
from routes import profile as profile_routes
|
|
from validate_constants import validate_shared_constants
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Create database tables on startup and validate constants."""
|
|
# Validate shared constants match backend definitions
|
|
validate_shared_constants()
|
|
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
allow_credentials=True,
|
|
)
|
|
|
|
# Include routers - modules with single router
|
|
app.include_router(auth_routes.router)
|
|
app.include_router(audit_routes.router)
|
|
app.include_router(exchange_routes.router)
|
|
app.include_router(profile_routes.router)
|
|
app.include_router(availability_routes.router)
|
|
app.include_router(meta_routes.router)
|
|
|
|
# Include routers - modules with multiple routers
|
|
for r in invites_routes.routers:
|
|
app.include_router(r)
|
|
for r in booking_routes.routers:
|
|
app.include_router(r)
|