2026-02-09 14:21:51 +01:00
|
|
|
from fastapi import FastAPI, Depends, HTTPException
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
from sqlalchemy import text
|
2026-02-09 14:25:58 +01:00
|
|
|
from app.database import get_db, engine
|
2026-02-09 14:29:13 +01:00
|
|
|
from app import models, seed
|
2026-02-09 14:36:01 +01:00
|
|
|
from app.routers import auth
|
2026-02-09 14:25:58 +01:00
|
|
|
|
|
|
|
|
# Create all tables
|
|
|
|
|
models.Base.metadata.create_all(bind=engine)
|
2026-02-09 14:16:38 +01:00
|
|
|
|
|
|
|
|
app = FastAPI(title="Card Game Backend")
|
|
|
|
|
|
2026-02-09 14:36:01 +01:00
|
|
|
app.include_router(auth.router)
|
|
|
|
|
|
2026-02-09 14:29:13 +01:00
|
|
|
@app.on_event("startup")
|
|
|
|
|
def startup_event():
|
|
|
|
|
db = next(get_db())
|
|
|
|
|
seed.seed_data(db)
|
|
|
|
|
|
2026-02-09 14:16:38 +01:00
|
|
|
@app.get("/health")
|
|
|
|
|
def health_check():
|
|
|
|
|
return {"status": "ok"}
|
2026-02-09 14:21:51 +01:00
|
|
|
|
2026-02-09 14:29:13 +01:00
|
|
|
@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()
|
|
|
|
|
|
2026-02-09 14:21:51 +01:00
|
|
|
@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)}")
|