summaryrefslogtreecommitdiff
path: root/opendc/api/v1/users/endpoint.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-25 13:50:49 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-25 13:50:49 +0200
commita1589e75358558eada7ffc2efc7e3fa7160d233e (patch)
tree7889a2364292cd8b90fe996da7907bebf200d3dc /opendc/api/v1/users/endpoint.py
parent1f34466d41ba01a3dd36b0866696367d397daf7e (diff)
Reformat codebase and fix spelling errors
Diffstat (limited to 'opendc/api/v1/users/endpoint.py')
-rw-r--r--opendc/api/v1/users/endpoint.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/opendc/api/v1/users/endpoint.py b/opendc/api/v1/users/endpoint.py
index 1c971b56..abd54f27 100644
--- a/opendc/api/v1/users/endpoint.py
+++ b/opendc/api/v1/users/endpoint.py
@@ -1,7 +1,8 @@
from opendc.models.user import User
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def GET(request):
"""Search for a User using their email address."""
@@ -9,14 +10,14 @@ def GET(request):
try:
request.check_required_parameters(
- query = {
+ query={
'email': 'string'
}
)
except exceptions.ParameterError as e:
return Response(400, e.message)
-
+
# Instantiate and read a User from the database
user = User.from_email(request.params_query['email'])
@@ -34,6 +35,7 @@ def GET(request):
user.to_JSON()
)
+
def POST(request):
"""Add a new User."""
@@ -41,7 +43,7 @@ def POST(request):
try:
request.check_required_parameters(
- body = {
+ body={
'user': {
'email': 'string'
}
@@ -52,12 +54,12 @@ def POST(request):
return Response(400, e.message)
# Instantiate a User
-
+
request.params_body['user']['googleId'] = request.google_id
user = User.from_JSON(request.params_body['user'])
# Make sure a User with this Google ID does not already exist
-
+
if user.exists('google_id'):
user = user.from_google_id(user.google_id)
return Response(409, '{} already exists.'.format(user))
@@ -65,7 +67,7 @@ def POST(request):
# Make sure this User is authorized to create this User
if not request.google_id == user.google_id:
- return Response(403, 'Fobidden from creating this User.')
+ return Response(403, 'Forbidden from creating this User.')
# Insert the User
@@ -74,7 +76,7 @@ def POST(request):
# Return a JSON representation of the User
return Response(
- 200,
- 'Successfully created {}'.format(user),
+ 200,
+ 'Successfully created {}'.format(user),
user.to_JSON()
)