From f25d2ec588272fae16bcb80c1a91e0ee553423e8 Mon Sep 17 00:00:00 2001 From: Matthew Macdonald-Wallace Date: Mon, 4 Sep 2023 19:47:45 +0100 Subject: [PATCH 1/2] Add a view to get member details by screen name --- memberportal/api_admin_tools/urls.py | 5 +++++ memberportal/api_admin_tools/views.py | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/memberportal/api_admin_tools/urls.py b/memberportal/api_admin_tools/urls.py index c7ed06d7..1f9125e7 100644 --- a/memberportal/api_admin_tools/urls.py +++ b/memberportal/api_admin_tools/urls.py @@ -5,6 +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/members//state//", views.MemberState.as_view(), diff --git a/memberportal/api_admin_tools/views.py b/memberportal/api_admin_tools/views.py index f04af07a..6d2f308d 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 +from profile.models import User, UserEventLog, Profile from access.models import DoorLog, InterlockLog from access import models from .models import MemberTier, PaymentPlan @@ -379,6 +379,26 @@ 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. From dce96e999db584056abd5c6e6f68851ea75c9a55 Mon Sep 17 00:00:00 2001 From: Matthew Macdonald-Wallace Date: Thu, 5 Oct 2023 16:49:23 +0100 Subject: [PATCH 2/2] 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.