29 lines
841 B
Python
29 lines
841 B
Python
from fastapi import FastAPI
|
|
|
|
from app.config import Settings, get_settings
|
|
from app.db.session import create_db_engine, create_session_factory, initialize_schema
|
|
|
|
|
|
def create_app(settings: Settings | None = None) -> FastAPI:
|
|
resolved = settings or get_settings()
|
|
resolved.data_dir.mkdir(parents=True, exist_ok=True)
|
|
resolved.tokens_dir.mkdir(parents=True, exist_ok=True)
|
|
resolved.activities_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
app = FastAPI(title="MyWhoosh Garmin Sync")
|
|
app.state.settings = resolved
|
|
|
|
engine = create_db_engine(resolved.database_url)
|
|
initialize_schema(engine)
|
|
app.state.db_engine = engine
|
|
app.state.session_factory = create_session_factory(engine)
|
|
|
|
@app.get("/healthz")
|
|
def healthz() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|