diff --git a/backend/product/urls.py b/backend/product/urls.py index 70ce765..891a251 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -1,11 +1,12 @@ from django.urls import path, re_path -from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView, BotProductsView,BotProductDetailView +from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView, BotProductsView,BotProductDetailView,BotCategoryView urlpatterns = [ path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('bot', BotProductsView.as_view(), name='bot-products'), path('bot//', BotProductDetailView.as_view(), name='bot-product-detail'), path('categories', AllCategories.as_view(), name='all-categories'), + path('categories/bot', BotCategoryView.as_view(), name='bot-categories'), path('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'), re_path(r'^comments/(?P[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'), re_path(r'^(?P[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'), diff --git a/backend/product/views.py b/backend/product/views.py index 94f0975..5b267ec 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -471,4 +471,29 @@ class BotProductDetailView(APIView): 'name': product.name, 'banner' : product.bot_banner, 'link': f'https://heymlz.com/product/{product.slug}' - }) \ No newline at end of file + }) + +class BotCategorySerializer(serializers.ModelSerializer): + link = serializers.SerializerMethodField() + class Meta: + model = MainCategoryModel + fields = ['pk', 'name', 'link'] + def get_link(self, obj): + return f'https://heymlz.com/products/category/{obj.slug}' + +class BotCategoryView(APIView): + serializer_class = BotCategorySerializer + def get(self, request): + categories = MainCategoryModel.objects.all() + categories_ser = self.serializer_class(categories, many=True) + + if categories.exists(): + return Response({ + "success": True, + "categories": categories_ser.data + }) + else: + return Response({ + "success": False, + "categories": [] + }) \ No newline at end of file