From f5ad0fde3dcbb9a1f320d87b589de78e5159484f Mon Sep 17 00:00:00 2001 From: DingZQ Date: Sun, 21 Aug 2022 21:44:57 +0800 Subject: [PATCH] Add method to get nodes and links --- main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.py b/main.py index 07891c5..1a6f5f3 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,16 @@ async def fastapi_create_project(network: str): print(network) return network +@app.get("/getnodes/") +async def fastapi_get_nodes(network: str): + nodeCount = get_count(network, NODE_COUNT) + nodes = [] + for i in range(0, nodeCount.value + 1): + node_id = get_node_id(network, i) + nodes.append(node_id) + + return nodes + @app.post("/addnode/") async def fastapi_add_node(network: str, node: str): idx = add_node(network, node, JUNCTION) @@ -70,6 +80,16 @@ async def fastapi_set_node_coord(network: str, node: str, x: int, y: int): set_node_coord(network, node, x, y) return True +@app.get("/getlinks/") +async def fastapi_get_links(network: str): + linkCount = get_count(network, LINK_COUNT) + links = [] + for i in range(0, linkCount.value + 1): + link_id = get_link_id(network, i) + links.append(link_id) + + return links + @app.post("/addlink/") async def fastapi_add_link(network: str, link: str, fromNode: str, toNode: str): idx = add_link(network, link, PIPE, fromNode, toNode)