- 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
32 lines
593 B
Python
32 lines
593 B
Python
from sqlalchemy.orm import Session
|
|
from models import Item
|
|
import random
|
|
|
|
def get_items(db: Session):
|
|
return db.query(Item).all()
|
|
|
|
def create_item(db: Session, title: str):
|
|
item = Item(title=title)
|
|
|
|
db.add(item)
|
|
db.commit()
|
|
db.refresh(item)
|
|
|
|
return item
|
|
|
|
def delete_item(db: Session, item_id: int):
|
|
item = db.query(Item).filter(Item.id == item_id).first()
|
|
|
|
if item:
|
|
db.delete(item)
|
|
db.commit()
|
|
|
|
return item
|
|
|
|
def spin_wheel(db: Session):
|
|
items = db.query(Item).all()
|
|
|
|
if not items:
|
|
return None
|
|
|
|
return random.choice(items) |