summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-06-30 18:02:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:44:16 +0200
commit6a4703517e7e1ca5ee2c8d8e0a4c49f32d17c662 (patch)
treea6f228becf7bcaadb2a885ef4349901220d1f3f8 /web-server/opendc/api/v2/topologies/topologyId/endpoint.py
parentc78432a639979283b309a03f41589b9823bcaaf7 (diff)
Topologies completed
Diffstat (limited to 'web-server/opendc/api/v2/topologies/topologyId/endpoint.py')
-rw-r--r--web-server/opendc/api/v2/topologies/topologyId/endpoint.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
index f0c12876..32e2dc8a 100644
--- a/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
+++ b/web-server/opendc/api/v2/topologies/topologyId/endpoint.py
@@ -1,7 +1,12 @@
+from datetime import datetime
+
+from opendc.util.database import Database
+from opendc.models.simulation import Simulation
from opendc.models.topology import Topology
from opendc.util.rest import Response
+
def GET(request):
"""Get this Topology."""
@@ -16,7 +21,25 @@ def GET(request):
def PUT(request):
"""Update this topology"""
- print(request)
+ request.check_required_parameters(path={'topologyId': 'int'},
+ body={
+ 'topology': {
+ 'name': 'string',
+ 'rooms': {}
+ }
+ })
+ topology = Topology.from_id(request.params_path['topologyId'])
+
+ topology.check_exists()
+ topology.check_user_access(request.google_id, True)
+
+ topology.set_property('name', request.params_body['topology']['name'])
+ topology.set_property('rooms', request.params_body['topology']['rooms'])
+ topology.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+
+ topology.update()
+
+ return Response(200, 'Successfully updated topology.', topology.obj)
def DELETE(request):
"""Delete this topology"""
@@ -25,6 +48,14 @@ def DELETE(request):
topology = Topology.from_id(request.params_path['topologyId'])
topology.check_exists()
+ topology.check_user_access(request.google_id, True)
+
+ simulation = Simulation.from_id(topology.obj['simulationId'])
+ simulation.check_exists()
+ if request.params_path['topologyId'] in simulation.obj['topologyIds']:
+ simulation.obj['topologyIds'].remove(request.params_path['topologyId'])
+ simulation.update()
+
topology.delete()
return Response(200, 'Successfully deleted topology.', topology.obj)