Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_user_by_id #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions user_backend/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ class UserService(APIView):
def get(self, request, format=None):
"""
Get data of a user.
QUERY PARAMETER: email="[email protected]"
QUERY PARAMETER: email="[email protected]"* OR id=<UID>
"""
email = request.GET.get('email')
user = get_user_by_email(email)
id = request.GET.get('id')
if email:
user = get_user_by_email(email)
elif id:
user = get_user_by_id(id)
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
serializer = UserSerializer(user)
return Response(serializer.data)

Expand Down Expand Up @@ -184,6 +190,15 @@ def get_user_by_email(email):
except:
raise Http404

def get_user_by_id(id):
"""
Returns user based on public key
"""
try:
return User.objects.get(id=id)
except:
raise Http404

def get_user_by_pk(pk):
try:
return User.objects.get(pk=pk)
Expand Down