- Add Alembic configuration (alembic.ini, env.py) for database migrations - Remove legacy wheel.db and unnecessary __pycache__ files - Delete models.py to separate SQLAlchemy and Pydantic concerns - Restructure main.py to use modular API routers (user/admin) - Introduce config backend for centralized settings management
38 lines
784 B
Plaintext
38 lines
784 B
Plaintext
from fastapi import FastAPI, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
import models
|
|
import schemas
|
|
import crud
|
|
|
|
from database import SessionLocal, engine
|
|
|
|
models.Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
# SPIN
|
|
@app.post("/spin")
|
|
def spin(db: Session = Depends(get_db)):
|
|
|
|
winner = crud.spin_wheel(db)
|
|
|
|
if not winner:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="No items available"
|
|
)
|
|
|
|
return {
|
|
"winner": {
|
|
"id": winner.id,
|
|
"title": winner.title
|
|
}
|
|
}
|
|
|
|
# GET ITEMS
|
|
@app.get("/items", response_model=list[schemas.ItemResponse])
|
|
def get_items(db: Session = Depends(get_db)):
|
|
return crud.get_items(db) |