summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-25 16:01:14 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-25 16:01:14 +0200
commitcd0b45627f0d8da8c8dc4edde223f3c36e9bcfbf (patch)
tree6ae1681630a0e270c23804e6dbb3bd414ebe5d6e /opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
parent128a1db017545597a5c035b7960eb3fd36b5f987 (diff)
build: Migrate to flat project structure
This change updates the project structure to become flattened. Previously, the simulator, frontend and API each lived into their own directory. With this change, all modules of the project live in the top-level directory of the repository. This should improve discoverability of modules of the project.
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py')
-rw-r--r--opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py b/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
new file mode 100644
index 00000000..bf031382
--- /dev/null
+++ b/opendc-web/opendc-web-api/opendc/api/v2/projects/endpoint.py
@@ -0,0 +1,32 @@
+from datetime import datetime
+
+from opendc.models.project import Project
+from opendc.models.topology import Topology
+from opendc.models.user import User
+from opendc.util.database import Database
+from opendc.util.rest import Response
+
+
+def POST(request):
+ """Create a new project, and return that new project."""
+
+ request.check_required_parameters(body={'project': {'name': 'string'}})
+
+ topology = Topology({'name': 'Default topology', 'rooms': []})
+ topology.insert()
+
+ project = Project(request.params_body['project'])
+ project.set_property('datetimeCreated', Database.datetime_to_string(datetime.now()))
+ project.set_property('datetimeLastEdited', Database.datetime_to_string(datetime.now()))
+ project.set_property('topologyIds', [topology.get_id()])
+ project.set_property('portfolioIds', [])
+ project.insert()
+
+ topology.set_property('projectId', project.get_id())
+ topology.update()
+
+ user = User.from_google_id(request.google_id)
+ user.obj['authorizations'].append({'projectId': project.get_id(), 'authorizationLevel': 'OWN'})
+ user.update()
+
+ return Response(200, 'Successfully created project.', project.obj)