refactor: restructure project into layered architecture

This commit is contained in:
2026-05-17 03:36:28 +03:30
parent b4971fcb6a
commit be6e1fab8e
29 changed files with 240 additions and 302 deletions

59
backend/api/user.py Normal file
View File

@@ -0,0 +1,59 @@
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
router = APIRouter()
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)
):
return crud.get_items(db)
# SPIN
@router.post("/spin")
def spin(
db: Session = Depends(get_db)
):
winner = crud.spin_wheel(db)
if not winner:
raise HTTPException(
status_code=400,
detail="No items available"
)
return {
"winner": {
"id": winner.id,
"title": winner.title
}
}