refactor: integrate Alembic, restructure project, and clean up
- 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
This commit is contained in:
32
backend/services/crud.py
Normal file
32
backend/services/crud.py
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user