f32203b630
- FastAPI + SQLite backend with routers for diagrams, devices, wires, bundles, connectors, export, and Octopart/Nexar search - Konva.js canvas: ortho/direct/curved routing, wire crossings, harness mode, snap-to-grid, multi-select, drag, resize, undo - Wire features: color/stripe, twisted pair helix, shielded glow, gauge size label, multi-core bundle grouping, length/unit tracking - Device library: connector, terminal block, cable, splice, label, group, relay, fuse, switch, component with custom connector support - Exports: BOM CSV, assembly TXT, JSON, formboard layout, PNG image - Auto-migration for schema changes via ALTER TABLE at startup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from typing import List
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from .. import models, schemas
|
|
from ..database import get_db
|
|
|
|
router = APIRouter(tags=["bundles"])
|
|
|
|
|
|
@router.get("/diagram/{diagram_id}", response_model=List[schemas.WireBundleOut])
|
|
def list_bundles(diagram_id: int, db: Session = Depends(get_db)):
|
|
return db.query(models.WireBundle).filter(models.WireBundle.diagram_id == diagram_id).all()
|
|
|
|
|
|
@router.post("/", response_model=schemas.WireBundleOut, status_code=201)
|
|
def create_bundle(payload: schemas.WireBundleCreate, db: Session = Depends(get_db)):
|
|
bundle = models.WireBundle(**payload.model_dump())
|
|
db.add(bundle)
|
|
db.commit()
|
|
db.refresh(bundle)
|
|
return bundle
|
|
|
|
|
|
@router.patch("/{bundle_id}", response_model=schemas.WireBundleOut)
|
|
def update_bundle(bundle_id: int, payload: schemas.WireBundleUpdate, db: Session = Depends(get_db)):
|
|
bundle = db.get(models.WireBundle, bundle_id)
|
|
if not bundle:
|
|
raise HTTPException(404, "Bundle not found")
|
|
for k, v in payload.model_dump(exclude_unset=True).items():
|
|
setattr(bundle, k, v)
|
|
db.commit()
|
|
db.refresh(bundle)
|
|
return bundle
|
|
|
|
|
|
@router.delete("/{bundle_id}", status_code=204)
|
|
def delete_bundle(bundle_id: int, db: Session = Depends(get_db)):
|
|
bundle = db.get(models.WireBundle, bundle_id)
|
|
if not bundle:
|
|
raise HTTPException(404, "Bundle not found")
|
|
# Detach wires before deleting
|
|
for wire in bundle.wires:
|
|
wire.bundle_id = None
|
|
db.delete(bundle)
|
|
db.commit()
|