Refine fastapi code
This commit is contained in:
149
main.py
149
main.py
@@ -31,7 +31,7 @@ if not os.path.exists(tmpDir):
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# project operations
|
||||
### project
|
||||
|
||||
@app.get('/listprojects/')
|
||||
async def fastapi_list_projects() -> list[str]:
|
||||
@@ -46,10 +46,19 @@ async def fastapi_create_project(network: str):
|
||||
create_project(network)
|
||||
return network
|
||||
|
||||
@app.post("/deleteproject/")
|
||||
async def fastapi_delete_project(network: str):
|
||||
delete_project(network)
|
||||
return True
|
||||
|
||||
@app.get("/isprojectopen/")
|
||||
async def fastapi_is_project_open(network: str):
|
||||
return is_project_open(network)
|
||||
|
||||
@app.get('/getprojectopencount/')
|
||||
async def fastapi_get_project_open_count(network: str) -> int:
|
||||
return get_project_open_count(network)
|
||||
|
||||
@app.post("/openproject/")
|
||||
async def fastapi_open_project(network: str):
|
||||
open_project(network)
|
||||
@@ -60,11 +69,6 @@ async def fastapi_close_project(network: str):
|
||||
close_project(network)
|
||||
return True
|
||||
|
||||
@app.post("/deleteproject/")
|
||||
async def fastapi_delete_project(network: str):
|
||||
delete_project(network)
|
||||
return True
|
||||
|
||||
@app.post("/copyproject/")
|
||||
async def fastapi_copy_project(source: str, target: str):
|
||||
copy_project(source, target)
|
||||
@@ -108,18 +112,31 @@ async def fastapi_unlock_project(network: str, id: str):
|
||||
del lockedPrjs[network]
|
||||
return True
|
||||
|
||||
# undo/redo
|
||||
@app.post("/undo/")
|
||||
### operations
|
||||
|
||||
@app.get('/getcurrentoperationid/')
|
||||
async def fastapi_get_current_operaiton_id(network: str) -> int:
|
||||
return get_current_operation(network)
|
||||
|
||||
@app.post('/undo/')
|
||||
async def fastapi_undo(network: str):
|
||||
return execute_undo(network)
|
||||
|
||||
@app.post("/redo/")
|
||||
@app.post('/redo/')
|
||||
async def fastapi_redo(network: str):
|
||||
return execute_redo(network)
|
||||
|
||||
@app.get("/getcurrentoperationid/")
|
||||
async def fastapi_get_current_operaiton_id(network: str) -> int:
|
||||
return get_current_operation(network)
|
||||
@app.get('/havesnapshot/')
|
||||
async def fastapi_get_snapshot(network: str) -> bool:
|
||||
return have_snapshot(network)
|
||||
|
||||
@app.post('/takesnapshot/')
|
||||
def fastapi_take_snapshot(network: str, tag: str) -> int | None:
|
||||
return take_snapshot(network, tag)
|
||||
|
||||
@app.post('/picksnapshot/')
|
||||
def fastapi_pick_snapshot(network: str, tag: str, discard: bool = False) -> ChangeSet:
|
||||
return pick_snapshot(network, tag, discard)
|
||||
|
||||
@app.get("/syncwithserver/")
|
||||
async def fastapi_sync_with_server(network: str, operationid: int) -> ChangeSet:
|
||||
@@ -139,87 +156,74 @@ async def fastapi_execute_compressed_batch_commands(network: str, req: Request)-
|
||||
cs.operations = jo_root['operations']
|
||||
return execute_batch_command(network, cs)
|
||||
|
||||
@app.get("/havesnapshot/")
|
||||
async def fastapi_has_snapeshot(network: str, snapshot: str)-> int:
|
||||
return have_snapshot(network, snapshot)
|
||||
|
||||
@app.post("/takesnapshot/")
|
||||
async def fastapi_take_snapeshot(network: str, snapshot: str)-> int:
|
||||
return take_snapshot(network, snapshot)
|
||||
|
||||
@app.post("/picksnapshot/")
|
||||
async def fastapi_pick_snapeshot(network: str, snapshot: str)-> ChangeSet:
|
||||
return pick_snapshot(network, snapshot)
|
||||
|
||||
@app.post("/pickoperation/")
|
||||
async def fastapi_pick_operation(network: str, operation: int) -> ChangeSet:
|
||||
return pick_operation(network, operation)
|
||||
|
||||
@app.get("/getrestoreoperation/")
|
||||
async def fastapi_get_restore_operation(network : str) -> int:
|
||||
return get_restore_operation(network)
|
||||
|
||||
############################################################
|
||||
# type
|
||||
############################################################
|
||||
|
||||
@app.get('/isnode/')
|
||||
async def fastapi_is_node(network: str, node: str) -> bool:
|
||||
return is_node(network, node)
|
||||
|
||||
@app.get('/isjunction/')
|
||||
async def fastapi_is_junction(network: str, node: str) -> bool:
|
||||
return is_junction(network, node)
|
||||
|
||||
@app.get('/isreservoir/')
|
||||
async def fastapi_is_reservoir(network: str, node: str) -> bool:
|
||||
return is_reservoir(network, node)
|
||||
|
||||
@app.get('/istank/')
|
||||
async def fastapi_is_tank(network: str, node: str) -> bool:
|
||||
return is_tank(network, node)
|
||||
|
||||
@app.get('/islink/')
|
||||
async def fastapi_is_link(network: str, link: str) -> bool:
|
||||
return is_link(network, link)
|
||||
|
||||
@app.get('/ispipe/')
|
||||
async def fastapi_is_pipe(network: str, link: str) -> bool:
|
||||
return is_pipe(network, link)
|
||||
|
||||
@app.get('/ispump/')
|
||||
async def fastapi_is_pump(network: str, link: str) -> bool:
|
||||
return is_pump(network, link)
|
||||
|
||||
@app.get('/isvalve/')
|
||||
async def fastapi_is_valve(network: str, link: str) -> bool:
|
||||
return is_valve(network, link)
|
||||
|
||||
@app.get('/iscurve/')
|
||||
async def fastapi_is_curve(network: str, curve: str) -> bool:
|
||||
return is_curve(network, curve)
|
||||
|
||||
@app.get('/ispattern/')
|
||||
async def fastapi_is_pattern(network: str, pattern: str) -> bool:
|
||||
return is_pattern(network, pattern)
|
||||
|
||||
# node
|
||||
@app.get("/getnodes/")
|
||||
async def fastapi_get_nodes(network: str) -> list[str]:
|
||||
return get_nodes(network)
|
||||
|
||||
@app.get("/isnode/")
|
||||
async def fastapi_is_node(network: str, node: str) -> bool:
|
||||
return is_node(network, node)
|
||||
|
||||
@app.get("/isjunction/")
|
||||
async def fastapi_is_junction(network: str, node: str) -> bool:
|
||||
return is_junction(network, node)
|
||||
|
||||
@app.get("/isreservoir/")
|
||||
async def fastapi_is_reservoir(network: str, node: str) -> bool:
|
||||
return is_reservoir(network, node)
|
||||
|
||||
@app.get("/istank/")
|
||||
async def fastapi_is_tank(network: str, node: str) -> bool:
|
||||
return is_tank(network, node)
|
||||
|
||||
# link
|
||||
@app.get("/getlinks/")
|
||||
async def fastapi_get_links(network: str) -> list[str]:
|
||||
return get_links(network)
|
||||
|
||||
@app.get("/islink/")
|
||||
async def fastapi_is_link(network: str, link: str) -> bool:
|
||||
return is_link(network, link)
|
||||
|
||||
@app.get("/ispipe/")
|
||||
async def fastapi_is_pipe(network: str, link: str) -> bool:
|
||||
return is_pipe(network, link)
|
||||
|
||||
@app.get("/ispump/")
|
||||
async def fastapi_is_pump(network: str, link: str) -> bool:
|
||||
return is_pump(network, link)
|
||||
|
||||
@app.get("/isvalve/")
|
||||
async def is_valve(network: str, link: str) -> bool:
|
||||
return is_valve(network, link)
|
||||
|
||||
# curve
|
||||
@app.get("/getcurves/")
|
||||
async def fastapi_get_curves(network: str) -> list[str]:
|
||||
return get_curves(network)
|
||||
|
||||
@app.get("/iscurve/")
|
||||
async def fastapi_is_curve(network: str, curve: str) -> bool:
|
||||
return is_curve(network, curve)
|
||||
|
||||
# parttern
|
||||
@app.get("/getpatterns/")
|
||||
async def fastapi_get_patterns(network: str) -> list[str]:
|
||||
return get_patterns(network)
|
||||
|
||||
@app.get("/ispattern/")
|
||||
async def fastapi_is_curve(network: str, pattern: str) -> bool:
|
||||
return is_pattern(network, pattern)
|
||||
|
||||
|
||||
############################################################
|
||||
# title 1.[TITLE]
|
||||
############################################################
|
||||
@@ -231,6 +235,11 @@ async def fast_get_title_schema(network: str) -> dict[str, dict[str, Any]]:
|
||||
async def fast_get_title(network: str) -> dict[str, Any]:
|
||||
return get_title(network)
|
||||
|
||||
@app.get('/settitle/')
|
||||
async def fastapi_set_title(network: str, req: Request) -> ChangeSet:
|
||||
props = await req.json()
|
||||
return set_title(network, ChangeSet(props))
|
||||
|
||||
############################################################
|
||||
# junction 2.[JUNCTIONS]
|
||||
############################################################
|
||||
@@ -579,7 +588,7 @@ async def fastapi_get_tank_properties(network: str, tank: str) -> dict[str, Any]
|
||||
async def fastapi_set_tank_properties(network: str, tank: str, req: Request) -> ChangeSet:
|
||||
props = await req.json()
|
||||
ps = { 'id' : tank } | props
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
return set_tank(network, ChangeSet(ps))
|
||||
|
||||
############################################################
|
||||
# pipe 4.[PIPES]
|
||||
|
||||
@@ -100,6 +100,9 @@ OPTION_QUALITY_TRACE = api.OPTION_QUALITY_TRACE
|
||||
# project
|
||||
############################################################
|
||||
|
||||
def list_project() -> list[str]:
|
||||
return api.list_project()
|
||||
|
||||
def have_project(name: str) -> bool:
|
||||
return api.have_project(name)
|
||||
|
||||
@@ -146,9 +149,6 @@ def dump_output(path: str) -> str:
|
||||
# operation
|
||||
############################################################
|
||||
|
||||
def list_project() -> list[str]:
|
||||
return api.list_project()
|
||||
|
||||
def get_current_operation(name: str) -> int:
|
||||
return api.get_current_operation(name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user