diff options
Diffstat (limited to 'web-server/opendc/api/v2/topologies/topologyId/endpoint.py')
| -rw-r--r-- | web-server/opendc/api/v2/topologies/topologyId/endpoint.py | 33 |
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) |
