Files
trading-journal/backend/app.py

31 lines
684 B
Python
Raw Normal View History

2025-09-22 14:33:32 +02:00
import asyncio
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
from fastapi import FastAPI, status
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
import settings
from trading_journal import db
from trading_journal.dto import TradeCreate, TradeRead
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
API_BASE = "/api/v1"
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
_db = db.create_database(settings.settings.database_url)
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: # noqa: ARG001
await asyncio.to_thread(_db.init_db)
try:
yield
finally:
await asyncio.to_thread(_db.dispose)
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
app = FastAPI(lifespan=lifespan)
2025-09-11 18:24:36 +00:00
2025-09-22 14:33:32 +02:00
@app.get(f"{API_BASE}/status")
async def get_status() -> dict[str, str]:
return {"status": "ok"}