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:
37
backend/api/admin
Normal file
37
backend/api/admin
Normal file
@@ -0,0 +1,37 @@
|
||||
from fastapi import FastAPI, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
import models
|
||||
import schemas
|
||||
import crud
|
||||
|
||||
from database import SessionLocal, engine
|
||||
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# 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"}
|
||||
|
||||
# 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)
|
||||
Reference in New Issue
Block a user