From bafd1fbbcb13a4f66cfa5b1ad7d936ef1e94b625 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 7 Jul 2025 13:54:09 +0330 Subject: [PATCH] order products --- apps/authorization/api/v1/api.py | 2 +- apps/product/web/api/v1/product_api.py | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/authorization/api/v1/api.py b/apps/authorization/api/v1/api.py index bfcce8b..1687864 100644 --- a/apps/authorization/api/v1/api.py +++ b/apps/authorization/api/v1/api.py @@ -95,7 +95,7 @@ class UserRelationViewSet(viewsets.ModelViewSet): serializer_class = UserRelationSerializer def list(self, request, *args, **kwargs): - queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) + queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa page = self.paginate_queryset(queryset) if page is not None: diff --git a/apps/product/web/api/v1/product_api.py b/apps/product/web/api/v1/product_api.py index ebccd00..9375363 100644 --- a/apps/product/web/api/v1/product_api.py +++ b/apps/product/web/api/v1/product_api.py @@ -67,6 +67,34 @@ class ProductViewSet(viewsets.ModelViewSet): queryset = product_models.Product.objects.all() serializer_class = product_serializers.ProductSerializer + def list(self, request, *args, **kwargs): + queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa + + page = self.paginate_queryset(queryset) + if page is not None: + serializer = self.get_serializer(page, many=True) + return self.get_paginated_response(serializer.data) + + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data) + + @action( + methods=['get'], + detail=False, + url_path='quotas_statistics', + url_name='quotas_statistics', + name='quotas_statistics' + ) + @transaction.atomic + def quotas_statistics_by_product(self, request): + """ quota statistics of each product """ + + quotas_statistics = [] + for product in self.queryset: + quotas_statistics.append(product.quota_information()) + + return Response(quotas_statistics, status=status.HTTP_200_OK) + @action( methods=['put'], detail=True,