From c31cfd319c80841d4ce1418a84a16450e4e78762 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Sat, 5 Nov 2022 09:42:04 +0800 Subject: [PATCH] Add method addcurve and deletecurve --- main.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4cb0041..c20f97c 100644 --- a/main.py +++ b/main.py @@ -915,14 +915,29 @@ async def fastapi_set_pattern_properties(network: str, pattern: str, req: Reques async def fast_get_curve_schema(network: str) -> dict[str, dict[str, Any]]: return get_curve_schema(network) +@app.post("/addcurve/") +async def fastapi_add_curve(network: str, curve: str, c_type: str, req: Request) -> ChangeSet: + props = await req.json() + ps = { + 'id' : curve, + 'c_type': c_type + } | props + return add_curve(network, ChangeSet(ps)) + +@app.post("/deletecurve/") +async def fastapi_delete_curve(network: str, curve: str) -> ChangeSet: + ps = { 'id' : curve } + return delete_curve(network, ChangeSet(ps)) + @app.get("/getcurveproperties/") async def fastapi_get_curve_properties(network: str, curve: str) -> dict[str, Any]: return get_curve(network, curve) -# example: set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]})) +# example: set_curve(p, ChangeSet({'id' : 'c0', 'c_type' : CURVE_TYPE_PUMP, 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]})) @app.post("/setcurveproperties/") async def fastapi_set_curve_properties(network: str, curve: str, req: Request) -> ChangeSet: props = await req.json() + # c_type放到request中 ps = { 'id' : curve } | props return set_curve(network, ChangeSet(ps))