Files
fast_api_livetse/backend/api/admin.py
Anahita-Mahmoudi ec86cdc528 feat: implement advanced reward management and wheel customization
- 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
2026-06-10 14:55:07 +03:30

86 lines
2.5 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
import schemas
from schemas import ItemResponse
from services import crud
from app.db.session import SessionLocal
from core.logger import get_logger
router = APIRouter()
logger = get_logger('admin')
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
# GET ALL ITEMS
@router.get("/items", response_model=list[ItemResponse])
def get_items(db: Session = Depends(get_db)):
try:
items = crud.get_items(db)
logger.info(f"Items fetched: {len(items)} items")
return items
except Exception as e:
logger.critical(f"Unexpected error fetching items: {e}")
raise
# CREATE ITEM
@router.post("/items", response_model=ItemResponse)
def create_item(item: schemas.ItemCreate, db: Session = Depends(get_db)):
try:
result = crud.create_item(
db,
item.title,
item.prize,
item.description,
item.prize_type,
item.probability
)
logger.info(f"Item created: {item.title}")
return result
except Exception as e:
logger.critical(f"Unexpected error creating item: {e}")
raise
# UPDATE ITEM
@router.put("/items/{item_id}", response_model=ItemResponse)
def update_item(item_id: int, item: schemas.ItemUpdate, db: Session = Depends(get_db)):
try:
updated = crud.update_item(
db,
item_id,
item.title,
item.prize,
item.description,
item.prize_type,
item.probability
)
if not updated:
logger.warning(f"Item not found: {item_id}")
raise HTTPException(status_code=404, detail="Item not found")
logger.info(f"Item updated: {item_id}")
return updated
except HTTPException:
raise
except Exception as e:
logger.critical(f"Unexpected error updating item: {e}")
raise
# DELETE ITEM
@router.delete("/items/{item_id}")
def delete_item(item_id: int, db: Session = Depends(get_db)):
try:
item = crud.delete_item(db, item_id)
if not item:
logger.warning(f"Item not found: {item_id}")
raise HTTPException(status_code=404, detail="Item not found")
logger.info(f"Item deleted: {item_id}")
return {"message": "Item deleted"}
except HTTPException:
raise
except Exception as e:
logger.critical(f"Unexpected error deleting item: {e}")
raise