From 9ec74eef99d3bb14d8b3d2b27417d518028871c1 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Sat, 24 May 2025 20:17:15 +0330 Subject: [PATCH] remove categort type --- backend/product/views.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/backend/product/views.py b/backend/product/views.py index 95c8f24..e291685 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -95,12 +95,12 @@ class AllProductsView(APIView): description="slug category (send it with category type)", required=False, ), - OpenApiParameter( - name="category_type", - type=OpenApiTypes.STR, - required=False, - enum=['sub', 'main'], - ), + # OpenApiParameter( + # name="category_type", + # type=OpenApiTypes.STR, + # required=False, + # enum=['sub', 'main'], + # ), OpenApiParameter( name="price_gte", description="Filter products with price greater than or equal to this value.", @@ -161,22 +161,13 @@ class AllProductsView(APIView): def get(self, request): try: category_slug = request.query_params.get('category') - category_type = request.query_params.get('category_type') - - VALID_CATEGORY_TYPES = {'sub', 'main'} products = ProductModel.objects.all() if category_slug: - if category_type not in VALID_CATEGORY_TYPES: - return Response( - {"detail": "category_type must be one of ['sub', 'main']"}, - status=status.HTTP_400_BAD_REQUEST - ) - - if category_type == 'sub': + if 'category' in category_slug: sub_category = get_object_or_404(SubCategoryModel, slug=category_slug) products = ProductModel.objects.filter(category=sub_category) - else: # category_type == 'main' + else: main_category = get_object_or_404(MainCategoryModel, slug=category_slug) sub_categories = main_category.subcategorys.all() products = ProductModel.objects.filter(category__in=sub_categories)