From b6a4b61eedf7f9aac4fe36fd0174bdbb20e074b3 Mon Sep 17 00:00:00 2001 From: katrinan029 Date: Wed, 4 Sep 2024 16:57:08 +0000 Subject: [PATCH] feat: update response to include pagination --- .../api/v1/views/enterprise_customer.py | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/enterprise/api/v1/views/enterprise_customer.py b/enterprise/api/v1/views/enterprise_customer.py index bfa4d63a5..16fefff20 100644 --- a/enterprise/api/v1/views/enterprise_customer.py +++ b/enterprise/api/v1/views/enterprise_customer.py @@ -3,6 +3,7 @@ """ from urllib.parse import quote_plus, unquote +import uuid import crum from django_filters.rest_framework import DjangoFilterBackend @@ -124,17 +125,25 @@ def basic_list(self, request, *arg, **kwargs): # pylint: disable=unused-argument def support_tool(self, request, *arg, **kwargs): """ - Enterprise Customer's detail data for the support tool + Enterprise Customer's detail data with pagination for the support tool Supported query param: - - uuid: filter the enterprise customer uuid . + - user_query: filter the enterprise customer name. """ - enterprise_uuid = request.GET.get('uuid') + + user_query = self.request.query_params.get("user_query", None) queryset = self.get_queryset().order_by('name') - if enterprise_uuid: - queryset = queryset.filter(uuid=enterprise_uuid) - serializer = self.get_serializer(queryset, many=True) - return Response(serializer.data) + + if user_query: + try: + # check that the user query is a valid uuid, else, filter by slug or name + if uuid.UUID(str(user_query)): + queryset = queryset.filter(uuid=user_query) + except ValueError: + queryset = queryset.filter(Q(slug__icontains=user_query) | Q(name__icontains=user_query)) + page = self.paginate_queryset(queryset) + serializer = self.get_serializer(page, many=True) + return self.get_paginated_response(serializer.data) @has_any_permissions('enterprise.can_access_admin_dashboard', ENTERPRISE_CUSTOMER_PROVISIONING_ADMIN_ACCESS_PERMISSION)