summaryrefslogtreecommitdiff
path: root/opendc/api/v1/users
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
parent1f34466d41ba01a3dd36b0866696367d397daf7e (diff)
Reformat codebase and fix spelling errors
Diffstat (limited to 'opendc/api/v1/users')
-rw-r--r--opendc/api/v1/users/endpoint.py20
-rw-r--r--opendc/api/v1/users/userId/authorizations/endpoint.py5
-rw-r--r--opendc/api/v1/users/userId/endpoint.py20
3 files changed, 25 insertions, 20 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()
)
diff --git a/opendc/api/v1/users/userId/authorizations/endpoint.py b/opendc/api/v1/users/userId/authorizations/endpoint.py
index 2320456f..46ca12ba 100644
--- a/opendc/api/v1/users/userId/authorizations/endpoint.py
+++ b/opendc/api/v1/users/userId/authorizations/endpoint.py
@@ -1,8 +1,9 @@
from opendc.models.authorization import Authorization
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):
"""Get this User's Authorizations."""
@@ -10,7 +11,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'userId': 'int'
}
)
diff --git a/opendc/api/v1/users/userId/endpoint.py b/opendc/api/v1/users/userId/endpoint.py
index e4edc107..767c5d13 100644
--- a/opendc/api/v1/users/userId/endpoint.py
+++ b/opendc/api/v1/users/userId/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 DELETE(request):
"""Delete this user."""
@@ -9,7 +10,7 @@ def DELETE(request):
try:
request.check_required_parameters(
- path = {
+ path={
'userId': 'int'
}
)
@@ -37,10 +38,11 @@ def DELETE(request):
return Response(
200,
- 'Succesfully deleted {}'.format(user),
+ 'Successfully deleted {}'.format(user),
user.to_JSON()
)
+
def GET(request):
"""Get this User."""
@@ -48,7 +50,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'userId': 'int'
}
)
@@ -71,6 +73,7 @@ def GET(request):
user.to_JSON(),
)
+
def PUT(request):
"""Update this User's given name and/ or family name."""
@@ -78,13 +81,13 @@ def PUT(request):
try:
request.check_required_parameters(
- body = {
+ body={
'user': {
'givenName': 'string',
'familyName': 'string'
}
},
- path = {
+ path={
'userId': 'int'
}
)
@@ -103,9 +106,9 @@ def PUT(request):
if not user.google_id_has_at_least(request.google_id, 'OWN'):
return Response(403, 'Forbidden from editing {}.'.format(user))
-
+
# Update this User
-
+
user.given_name = request.params_body['user']['givenName']
user.family_name = request.params_body['user']['familyName']
@@ -118,4 +121,3 @@ def PUT(request):
'Successfully updated {}.'.format(user),
user.to_JSON()
)
-