diff --git a/backend/blog/views.py b/backend/blog/views.py index 5bd3628..f450023 100644 --- a/backend/blog/views.py +++ b/backend/blog/views.py @@ -6,14 +6,21 @@ from .serializers import AllBlogSerilizer, BlogSerilizer from django.shortcuts import get_object_or_404 from utils.pagination import StructurePagination from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes - +from django.db.models import Q class AllBlogView(APIView): serializer_class = AllBlogSerilizer pagination_class = StructurePagination + authentication_classes = [] @extend_schema( parameters=[ + OpenApiParameter( + name="search", + description="بگرددددد تو بلاااااگگگووووو", + required=False, + type=OpenApiTypes.STR, + ), OpenApiParameter( name="limit", description="لیمیتش", @@ -34,6 +41,9 @@ class AllBlogView(APIView): ) def get(self, request): blogs = BlogModel.objects.filter(is_published=True) + search_query = request.query_params.get('search', None) + if search_query: + blogs = blogs.filter(Q(title__icontains=search_query) | Q(content__icontains=search_query)) paginator = self.pagination_class() paginated_blogs = paginator.paginate_queryset(blogs, request) blog_ser = self.serializer_class(instance=paginated_blogs, many=True, context={'request': request}) @@ -43,7 +53,7 @@ class AllBlogView(APIView): class BlogView(APIView): serializer_class = BlogSerilizer - + authentication_classes = [] def get_client_ip(self, request): """Helper function to get the client IP from request headers.""" x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') diff --git a/backend/home/views.py b/backend/home/views.py index 815a2e4..8d78300 100644 --- a/backend/home/views.py +++ b/backend/home/views.py @@ -8,6 +8,7 @@ from rest_framework import status class HomeView(APIView): + authentication_classes = [] def get(self, request): dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique') diff --git a/backend/product/views.py b/backend/product/views.py index 260beb7..e0e8f2b 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -24,6 +24,7 @@ from rest_framework.permissions import AllowAny class AllCategories(APIView): serializer_class = MainCategorySerializer + authentication_classes = [] @extend_schema( # parameters=[ # OpenApiParameter( @@ -50,6 +51,7 @@ class AllCategories(APIView): class ProductView(APIView): serializer_class = ProductSerializer permission_classes = [AllowAny] + authentication_classes = [] def get(self, request, pk): product = get_object_or_404(ProductModel, id=pk) dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique') @@ -61,7 +63,7 @@ class ProductView(APIView): class AllProductsView(APIView): serializer_class = ProductSerializer pagination_class = StructurePagination - + authentication_classes = [] @extend_schema( parameters=[ OpenApiParameter( @@ -171,9 +173,7 @@ class AllProductsView(APIView): # Price filters price_gte = request.query_params.get('price_gte', None) price_lte = request.query_params.get('price_lte', None) - - if type(price_gte) != int or type(price_lte) != int: - return Response({'detail': 'value error price_gte and price_lte should be a number'}, status=status.HTTP_400_BAD_REQUEST) + if price_gte: products = products.filter(price__gte=price_gte) if price_lte: diff --git a/frontend/components/global/CategoryCard.vue b/frontend/components/global/CategoryCard.vue index d01749b..9a77401 100644 --- a/frontend/components/global/CategoryCard.vue +++ b/frontend/components/global/CategoryCard.vue @@ -24,10 +24,10 @@ const { colorObject } = useImageColor(`#category-image-${id.value}`);