from fastapi import FastAPI, Depends, HTTPException from sqlalchemy.orm import Session from sqlalchemy import text from app.database import get_db, engine from app import models, seed # Create all tables models.Base.metadata.create_all(bind=engine) app = FastAPI(title="Card Game Backend") @app.on_event("startup") def startup_event(): db = next(get_db()) seed.seed_data(db) @app.get("/health") def health_check(): return {"status": "ok"} @app.get("/catalog/cards") def get_cards(db: Session = Depends(get_db)): return db.query(models.Card).all() @app.get("/catalog/chests") def get_chests(db: Session = Depends(get_db)): return db.query(models.Chest).all() @app.get("/db-check") def db_check(db: Session = Depends(get_db)): try: # Execute simple query to check connection db.execute(text("SELECT 1")) return {"db": "ok"} except Exception as e: raise HTTPException(status_code=500, detail=f"Database connection failed: {str(e)}")