initial commit
This commit is contained in:
32
backend/crud.py
Normal file
32
backend/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