refactor: integrate Alembic, restructure project, and clean up
- Add Alembic configuration (alembic.ini, env.py) for database migrations - Remove legacy wheel.db and unnecessary __pycache__ files - Delete models.py to separate SQLAlchemy and Pydantic concerns - Restructure main.py to use modular API routers (user/admin) - Introduce config backend for centralized settings management
This commit is contained in:
@@ -21,59 +21,7 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Database Session
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# GET ITEMS
|
||||
@app.get("/items", response_model=list[schemas.ItemResponse])
|
||||
def get_items(db: Session = Depends(get_db)):
|
||||
return crud.get_items(db)
|
||||
|
||||
# CREATE ITEM
|
||||
@app.post("/items", response_model=schemas.ItemResponse)
|
||||
def create_item(
|
||||
item: schemas.ItemCreate,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
return crud.create_item(db, item.title)
|
||||
|
||||
# DELETE ITEM
|
||||
@app.delete("/items/{item_id}")
|
||||
def delete_item(
|
||||
item_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
item = crud.delete_item(db, item_id)
|
||||
|
||||
if not item:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Item not found"
|
||||
)
|
||||
|
||||
return {"message": "Item deleted"}
|
||||
|
||||
# SPIN
|
||||
@app.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
|
||||
}
|
||||
}
|
||||
app.include_router(user_router)
|
||||
app.include_router(admin_router)
|
||||
Reference in New Issue
Block a user