- 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>
22 lines
621 B
Python
22 lines
621 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db import get_db
|
|
from app.models.print_job import PrintJob
|
|
|
|
router = APIRouter(prefix="/jobs", tags=["jobs"])
|
|
|
|
|
|
@router.get("/")
|
|
def list_jobs(db: Session = Depends(get_db)):
|
|
return [j.to_dict() for j in db.query(PrintJob).all()]
|
|
|
|
|
|
@router.get("/{job_id}")
|
|
def get_job(job_id: int, db: Session = Depends(get_db)):
|
|
job = db.query(PrintJob).filter(PrintJob.id == job_id).first()
|
|
if not job:
|
|
from fastapi import HTTPException
|
|
raise HTTPException(status_code=404, detail="Job not found")
|
|
return job.to_dict()
|