Scaffold SQLAlchemy models, routers, and Alembic migrations
- app/models/: Printer, Filament, PrintJob, Todo, PricingConfig with full SQLAlchemy 2.x mapped columns and relationships - app/routers/: list + get-by-id endpoints for all five resources - app/db.py: SQLAlchemy engine + SessionLocal + get_db dependency - alembic/: env.py reads MYSQL_* env vars; 0001_initial_schema mirrors db.sql - alembic.ini: script_location configured, URL injected at runtime Since db.sql already created the tables, stamp the DB before running future migrations: alembic stamp head Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
21
app/routers/printers.py
Normal file
21
app/routers/printers.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import get_db
|
||||
from app.models.printer import Printer
|
||||
|
||||
router = APIRouter(prefix="/printers", tags=["printers"])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def list_printers(db: Session = Depends(get_db)):
|
||||
return [p.to_dict() for p in db.query(Printer).all()]
|
||||
|
||||
|
||||
@router.get("/{printer_id}")
|
||||
def get_printer(printer_id: int, db: Session = Depends(get_db)):
|
||||
printer = db.query(Printer).filter(Printer.id == printer_id).first()
|
||||
if not printer:
|
||||
from fastapi import HTTPException
|
||||
raise HTTPException(status_code=404, detail="Printer not found")
|
||||
return printer.to_dict()
|
||||
Reference in New Issue
Block a user