Skip to content

Commit

Permalink
Merge pull request #212 from MakeMonmouth/feature/get_single_user_pro…
Browse files Browse the repository at this point in the history
…file

Add a view to get member details by screen name
  • Loading branch information
jabelone authored Oct 7, 2023
2 parents 1f4a51c + dce96e9 commit 719e54a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions memberportal/api_admin_tools/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

urlpatterns = [
path("api/admin/members/", views.GetMembers.as_view(), name="GetMembers"),
# path(
# "api/admin/member/<str:screen_name>/",
# views.MemberProfileByName.as_view(),
# name="MemberProfileByName",
# ),
path(
"api/admin/members/<int:member_id>/state/<str:state>/",
views.MemberState.as_view(),
Expand Down
13 changes: 10 additions & 3 deletions memberportal/api_admin_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ class GetMembers(APIView):
permission_classes = (permissions.IsAdminUser,)

def get(self, request):
members = User.objects.select_related("profile").all()

filtered = []

for member in members:
memberId = request.GET.get("memberId")
if memberId is not None:
member = User.objects.select_related("profile").get(
profile__screen_name=memberId
)
filtered.append(member.profile.get_basic_profile())
else:
members = User.objects.select_related("profile").all()

for member in members:
filtered.append(member.profile.get_basic_profile())

return Response(filtered)

Expand Down

0 comments on commit 719e54a

Please sign in to comment.