remove categort type

This commit is contained in:
Parsa Nazer
2025-05-24 20:17:15 +03:30
parent d05b45f75f
commit 9ec74eef99
+8 -17
View File
@@ -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)