Update project files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ANDREW HOSFORD
2026-04-07 11:59:48 -05:00
parent dd227be9b0
commit 0e8978f48c
50 changed files with 5878 additions and 241 deletions

View File

@@ -29,14 +29,52 @@ def _to_detail_response(layout: GraphLayout) -> GraphLayoutDetailResponse:
)
AUTOSAVE_NAME = "__autosave__"
@router.get("", response_model=list[GraphLayoutResponse])
def list_layouts(project_id: int | None = None, db: Session = Depends(get_db)):
query = db.query(GraphLayout)
query = db.query(GraphLayout).filter(GraphLayout.name != AUTOSAVE_NAME)
if project_id is not None:
query = query.filter(GraphLayout.project_id == project_id)
return [_to_response(l) for l in query.order_by(GraphLayout.updated_at.desc()).all()]
@router.get("/autosave", response_model=GraphLayoutDetailResponse)
def get_autosave(db: Session = Depends(get_db)):
layout = db.query(GraphLayout).filter(GraphLayout.name == AUTOSAVE_NAME).first()
if not layout:
raise HTTPException(404, "No autosave layout found")
return _to_detail_response(layout)
@router.put("/autosave", response_model=GraphLayoutDetailResponse)
def upsert_autosave(data: GraphLayoutUpdate, db: Session = Depends(get_db)):
layout = db.query(GraphLayout).filter(GraphLayout.name == AUTOSAVE_NAME).first()
update_data = data.model_dump(exclude_unset=True)
if "node_positions" in update_data:
update_data["node_positions"] = json.dumps(update_data["node_positions"])
if "viewport" in update_data:
update_data["viewport"] = json.dumps(update_data["viewport"])
if layout:
for key, value in update_data.items():
setattr(layout, key, value)
else:
layout = GraphLayout(
name=AUTOSAVE_NAME,
description="Auto-saved working state",
node_positions=update_data.get("node_positions", "{}"),
viewport=update_data.get("viewport", "{}"),
is_default=False,
)
db.add(layout)
db.commit()
db.refresh(layout)
return _to_detail_response(layout)
@router.get("/{layout_id}", response_model=GraphLayoutDetailResponse)
def get_layout(layout_id: int, db: Session = Depends(get_db)):
layout = db.get(GraphLayout, layout_id)