erste Funktionierende Fassung
This commit is contained in:
@@ -3,6 +3,7 @@ PlantPlan FastAPI Backend
|
||||
- Symbolbibliothek ausliefern
|
||||
- Koordinaten normalisieren
|
||||
- JSON/SVG Export
|
||||
- Shape-Änderungen empfangen (Puffer + Kreisel)
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -24,14 +25,42 @@ app.add_middleware(
|
||||
CATALOG_DIR = Path(__file__).parent / "catalog"
|
||||
|
||||
|
||||
# --- Models ---
|
||||
# ---------------------------------------------------------------------------
|
||||
# Pydantic Models
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class SketchPayload(BaseModel):
|
||||
shapes: list[dict]
|
||||
grid_size: int = 10
|
||||
|
||||
|
||||
# --- Endpoints ---
|
||||
class PufferUpdate(BaseModel):
|
||||
"""Puffer-Symbol: Rechteck mit Breite und Höhe."""
|
||||
id: str
|
||||
x: float
|
||||
y: float
|
||||
w: float # Breite
|
||||
h: float # Höhe
|
||||
|
||||
|
||||
class KreiselUpdate(BaseModel):
|
||||
"""Kreisel-Symbol: Zwei Kreise mit Abstand und Radius."""
|
||||
id: str
|
||||
x: float
|
||||
y: float
|
||||
abstand: float # Abstand zwischen den Kreismittelpunkten
|
||||
radius: float # Radius beider Kreise
|
||||
|
||||
|
||||
class ShapeUpdatePayload(BaseModel):
|
||||
"""Payload für Shape-Änderungen vom Client."""
|
||||
puffer: list[PufferUpdate] = []
|
||||
kreisel: list[KreiselUpdate] = []
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.get("/symbols")
|
||||
async def get_symbols():
|
||||
@@ -64,3 +93,42 @@ async def export_sketch(payload: SketchPayload):
|
||||
"shapes": payload.shapes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@app.post("/shapes/update")
|
||||
async def update_shapes(payload: ShapeUpdatePayload):
|
||||
"""
|
||||
Shape-Änderungen vom Client empfangen.
|
||||
|
||||
Gibt für jeden Puffer Breite/Höhe und für jeden Kreisel
|
||||
Abstand/Radius + berechnete Gesamtlänge zurück.
|
||||
"""
|
||||
result = {
|
||||
"received": {
|
||||
"puffer_count": len(payload.puffer),
|
||||
"kreisel_count": len(payload.kreisel),
|
||||
},
|
||||
"puffer": [],
|
||||
"kreisel": [],
|
||||
}
|
||||
|
||||
for p in payload.puffer:
|
||||
result["puffer"].append({
|
||||
"id": p.id,
|
||||
"x": p.x,
|
||||
"y": p.y,
|
||||
"breite": p.w,
|
||||
"hoehe": p.h,
|
||||
})
|
||||
|
||||
for k in payload.kreisel:
|
||||
result["kreisel"].append({
|
||||
"id": k.id,
|
||||
"x": k.x,
|
||||
"y": k.y,
|
||||
"abstand": k.abstand,
|
||||
"radius": k.radius,
|
||||
"gesamtlaenge": 2 * k.radius + k.abstand,
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user