Add addNodeWithCoord
This commit is contained in:
26
main.py
26
main.py
@@ -1,3 +1,5 @@
|
|||||||
|
from itertools import count
|
||||||
|
from netrc import netrc
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
@@ -27,7 +29,7 @@ if not os.path.exists(tmpDir):
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# project operations
|
# undo/redo
|
||||||
@app.post("/undo/")
|
@app.post("/undo/")
|
||||||
async def fastapi_undo(network: str):
|
async def fastapi_undo(network: str):
|
||||||
undo(network)
|
undo(network)
|
||||||
@@ -40,6 +42,7 @@ async def fastapi_redo(network: str):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# project operations
|
||||||
@app.get("/haveproject/")
|
@app.get("/haveproject/")
|
||||||
async def fastapi_have_project(network: str):
|
async def fastapi_have_project(network: str):
|
||||||
return have_project(network)
|
return have_project(network)
|
||||||
@@ -62,6 +65,7 @@ async def fastapi_delete_project(network: str):
|
|||||||
delete_project(network)
|
delete_project(network)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# element operations
|
||||||
@app.get("/getnodes/")
|
@app.get("/getnodes/")
|
||||||
async def fastapi_get_nodes(network: str):
|
async def fastapi_get_nodes(network: str):
|
||||||
nodeCount = get_count(network, NODE_COUNT)
|
nodeCount = get_count(network, NODE_COUNT)
|
||||||
@@ -80,6 +84,17 @@ async def fastapi_add_node(network: str, node: str):
|
|||||||
print("add node")
|
print("add node")
|
||||||
count = get_count(network, NODE_COUNT)
|
count = get_count(network, NODE_COUNT)
|
||||||
print(count.value)
|
print(count.value)
|
||||||
|
|
||||||
|
return idx
|
||||||
|
|
||||||
|
@app.post("/addnodewithcoord/")
|
||||||
|
async def fastapi_add_node_with_coord(network: str, node: str, x: int, y: int):
|
||||||
|
idx = add_node(network, node, JUNCTION)
|
||||||
|
print(idx)
|
||||||
|
count = get_count(network, NODE_COUNT)
|
||||||
|
print(count.value)
|
||||||
|
set_node_coord(network, node, x, y)
|
||||||
|
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
@app.post("/deletenode/")
|
@app.post("/deletenode/")
|
||||||
@@ -91,6 +106,7 @@ async def fastapi_delete_node(network: str, node: str):
|
|||||||
async def fastapi_count_node(network: str):
|
async def fastapi_count_node(network: str):
|
||||||
count = get_count(network, NODE_COUNT)
|
count = get_count(network, NODE_COUNT)
|
||||||
print(count)
|
print(count)
|
||||||
|
|
||||||
return count.value
|
return count.value
|
||||||
|
|
||||||
@app.get("/getnodecoord/")
|
@app.get("/getnodecoord/")
|
||||||
@@ -105,6 +121,7 @@ async def fastapi_get_node_coord(network: str, node: str):
|
|||||||
@app.post("/setnodecoord/")
|
@app.post("/setnodecoord/")
|
||||||
async def fastapi_set_node_coord(network: str, node: str, x: int, y: int):
|
async def fastapi_set_node_coord(network: str, node: str, x: int, y: int):
|
||||||
set_node_coord(network, node, x, y)
|
set_node_coord(network, node, x, y)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@app.get("/getlinks/")
|
@app.get("/getlinks/")
|
||||||
@@ -122,17 +139,20 @@ async def fastapi_get_links(network: str):
|
|||||||
async def fastapi_add_link(network: str, link: str, fromNode: str, toNode: str):
|
async def fastapi_add_link(network: str, link: str, fromNode: str, toNode: str):
|
||||||
idx = add_link(network, link, PIPE, fromNode, toNode)
|
idx = add_link(network, link, PIPE, fromNode, toNode)
|
||||||
print(idx)
|
print(idx)
|
||||||
|
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
@app.post("/deletelink/")
|
@app.post("/deletelink/")
|
||||||
async def fastapi_delete_link(network: str, link: str):
|
async def fastapi_delete_link(network: str, link: str):
|
||||||
delete_link(network, link)
|
delete_link(network, link)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@app.get("/countlink/")
|
@app.get("/countlink/")
|
||||||
async def fastapi_count_link(network: str):
|
async def fastapi_count_link(network: str):
|
||||||
count = get_count(network, LINK_COUNT)
|
count = get_count(network, LINK_COUNT)
|
||||||
print(count)
|
print(count)
|
||||||
|
|
||||||
return count.value
|
return count.value
|
||||||
|
|
||||||
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
|
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
|
||||||
@@ -142,6 +162,8 @@ async def upload_inp(file: bytes = File(), name: str = None):
|
|||||||
f.write(file)
|
f.write(file)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
@app.get("/downloadinp/", status_code=status.HTTP_200_OK)
|
@app.get("/downloadinp/", status_code=status.HTTP_200_OK)
|
||||||
async def download_inp(name: str, response: Response):
|
async def download_inp(name: str, response: Response):
|
||||||
filePath = inpDir + name
|
filePath = inpDir + name
|
||||||
@@ -149,6 +171,8 @@ async def download_inp(name: str, response: Response):
|
|||||||
return FileResponse(filePath, media_type='application/octet-stream', filename="inp.inp")
|
return FileResponse(filePath, media_type='application/octet-stream', filename="inp.inp")
|
||||||
else:
|
else:
|
||||||
response.status_code = status.HTTP_400_BAD_REQUEST
|
response.status_code = status.HTTP_400_BAD_REQUEST
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user