Skip to content

Commit

Permalink
Update API view to take a querystring of memberId and filter accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
proffalken committed Oct 5, 2023
1 parent 190e96b commit e35cc9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
10 changes: 5 additions & 5 deletions memberportal/api_admin_tools/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +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/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
35 changes: 11 additions & 24 deletions memberportal/api_admin_tools/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down 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 Expand Up @@ -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.
Expand Down

0 comments on commit e35cc9e

Please sign in to comment.