summaryrefslogtreecommitdiff
path: root/opendc/api/v2/users/endpoint.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-23 19:06:38 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-06-23 19:06:38 +0200
commit6fdb3e75dad15523d996e457c216647755b29101 (patch)
tree02590e4b4219613b6dbe70e10130bee19310290d /opendc/api/v2/users/endpoint.py
parentc14ff547d4f6b6569bab3293ee574b03a8770ae3 (diff)
Revamp one endpoint as experiment
Diffstat (limited to 'opendc/api/v2/users/endpoint.py')
-rw-r--r--opendc/api/v2/users/endpoint.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/opendc/api/v2/users/endpoint.py b/opendc/api/v2/users/endpoint.py
index abd54f27..83949fcf 100644
--- a/opendc/api/v2/users/endpoint.py
+++ b/opendc/api/v2/users/endpoint.py
@@ -1,33 +1,25 @@
from opendc.models.user import User
from opendc.util import exceptions
+from opendc.util.database import fetch_one
from opendc.util.rest import Response
def GET(request):
"""Search for a User using their email address."""
- # Make sure required parameters are there
-
try:
request.check_required_parameters(
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'])
-
- # Make sure this User exists in the database
-
- if not user.exists():
- return Response(404, '{} not found'.format(user))
+ user = fetch_one({'email': request.params_query['email']}, 'users')
- # Return this User
+ if user is not None:
+ return Response(404, f'User with email {request.params_query["email"]} not found')
return Response(
200,