Files
fast_api_livetse/backend/api/user.py
Anahita-Mahmoudi ed82bf7f1f git add .
git commit -m "feat: improve wheel UI with gold pointer and center circle sync"
2026-05-30 13:29:48 +03:30

41 lines
878 B
Python

from fastapi import APIRouter
from fastapi import Depends
from fastapi import HTTPException
from sqlalchemy.orm import Session
import schemas
from services import crud
from app.db.session import SessionLocal
from core.logger import get_logger
router = APIRouter()
logger = get_logger('user')
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
# GET ITEMS
@router.get("/items", response_model=list[schemas.ItemResponse])
def get_items(db: Session = Depends(get_db)):
try:
items = crud.get_items(db)
logger.info(f"User fetched items: {len(items)} items")
return items
except Exception as e:
logger.error(f"Error fetching items: {e}")
raise
# SPIN
@router.post("/spin")
def spin(db: Session = Depends(get_db)):
try:
winner = crud.spin_wheel(db)
if not winner: