From e35cc9e6b43e65cc6d3b99fb25c32cda5aa97306 Mon Sep 17 00:00:00 2001 From: Matthew Macdonald-Wallace Date: Thu, 5 Oct 2023 16:49:23 +0100 Subject: [PATCH] Update API view to take a querystring of memberId and filter accordingly --- memberportal/api_admin_tools/urls.py | 10 ++++---- memberportal/api_admin_tools/views.py | 35 +++++++++------------------ 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/memberportal/api_admin_tools/urls.py b/memberportal/api_admin_tools/urls.py index 1f9125e7..686c1489 100644 --- a/memberportal/api_admin_tools/urls.py +++ b/memberportal/api_admin_tools/urls.py @@ -5,11 +5,11 @@ urlpatterns = [ path("api/admin/members/", views.GetMembers.as_view(), name="GetMembers"), - path( - "api/admin/member//", - views.MemberProfileByName.as_view(), - name="MemberProfileByName", - ), + # path( + # "api/admin/member//", + # views.MemberProfileByName.as_view(), + # name="MemberProfileByName", + # ), path( "api/admin/members//state//", views.MemberState.as_view(), diff --git a/memberportal/api_admin_tools/views.py b/memberportal/api_admin_tools/views.py index 6d2f308d..f784710b 100644 --- a/memberportal/api_admin_tools/views.py +++ b/memberportal/api_admin_tools/views.py @@ -1,4 +1,4 @@ -from profile.models import User, UserEventLog, Profile +from profile.models import User, UserEventLog from access.models import DoorLog, InterlockLog from access import models from .models import MemberTier, PaymentPlan @@ -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) @@ -379,26 +386,6 @@ def put(self, request, member_id): return Response() -class MemberProfileByName(APIView): - """ - get: This method gets a specific member's profile. - """ - - permission_classes = (permissions.IsAdminUser,) - - def get(self, request, screen_name=None): - member = {} - if not screen_name: - return Response(status=status.HTTP_400_BAD_REQUEST) - - member_object = Profile.objects.get(screen_name=screen_name) - member["screen_name"] = member_object.screen_name - member["rfid_token"] = member_object.rfid - member["email_address"] = member_object.user.email - - return Response(member) - - class MemberTiers(StripeAPIView): """ get: gets a list of all membership plans.