- Add customizable background color - Add wheel animations and sound effects - Add reward description field and winner modal - Change font to Dana - Add configurable reward probabilities - Support reward types (Empty, Discount Code, LiveCoin) - Replace reward title with reward type selector - Allow wheel page title customization from admin panel
66 lines
1.5 KiB
Python
66 lines
1.5 KiB
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.critical(f"Unexpected 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:
|
|
logger.warning("Spin attempted but no items available")
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="No items available"
|
|
)
|
|
|
|
logger.info(f"Spin result: {winner.title}")
|
|
|
|
return {
|
|
"winner": {
|
|
"id": winner.id,
|
|
"title": winner.title,
|
|
"prize": winner.prize,
|
|
"prize_type": winner.prize_type,
|
|
"description": winner.description or ""
|
|
}
|
|
}
|
|
|
|
except HTTPException:
|
|
raise
|
|
|
|
except Exception as e:
|
|
logger.critical(f"Unexpected error during spin: {e}")
|
|
raise |