From 565ede0dc50c3b2df09c066ea3a28a4901cce547 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 23 Jun 2020 18:08:28 +0200 Subject: Add DB handlers and rename to v2 --- opendc/api/v1/simulations/endpoint.py | 87 ----------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 opendc/api/v1/simulations/endpoint.py (limited to 'opendc/api/v1/simulations/endpoint.py') diff --git a/opendc/api/v1/simulations/endpoint.py b/opendc/api/v1/simulations/endpoint.py deleted file mode 100644 index a8637728..00000000 --- a/opendc/api/v1/simulations/endpoint.py +++ /dev/null @@ -1,87 +0,0 @@ -from datetime import datetime - -from opendc.models.authorization import Authorization -from opendc.models.datacenter import Datacenter -from opendc.models.path import Path -from opendc.models.section import Section -from opendc.models.simulation import Simulation -from opendc.models.user import User -from opendc.util import database, exceptions -from opendc.util.rest import Response - - -def POST(request): - """Create a new simulation, and return that new simulation.""" - - # Make sure required parameters are there - - try: - request.check_required_parameters( - body={ - 'simulation': { - 'name': 'string' - } - } - ) - - except exceptions.ParameterError as e: - return Response(400, e.message) - - # Instantiate a Simulation - - simulation_data = request.params_body['simulation'] - - simulation_data['datetimeCreated'] = database.datetime_to_string(datetime.now()) - simulation_data['datetimeLastEdited'] = database.datetime_to_string(datetime.now()) - - simulation = Simulation.from_JSON(simulation_data) - - # Insert this Simulation into the database - - simulation.insert() - - # Instantiate an Authorization and insert it into the database - - authorization = Authorization( - user_id=User.from_google_id(request.google_id).id, - simulation_id=simulation.id, - authorization_level='OWN' - ) - - authorization.insert() - - # Instantiate a Path and insert it into the database - - path = Path( - simulation_id=simulation.id, - datetime_created=database.datetime_to_string(datetime.now()) - ) - - path.insert() - - # Instantiate a Datacenter and insert it into the database - - datacenter = Datacenter( - starred=0, - simulation_id=simulation.id - ) - - datacenter.insert() - - # Instantiate a Section and insert it into the database - - section = Section( - path_id=path.id, - datacenter_id=datacenter.id, - start_tick=0 - ) - - section.insert() - - # Return this Simulation - - return Response( - 200, - 'Successfully created {}.'.format(simulation), - simulation.to_JSON() - ) -- cgit v1.2.3