From 8087f3aaa54acd2690340a2f01b2d7326c1191dd Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 13:59:25 +0330 Subject: [PATCH 1/5] fix url --- backend/product/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/product/urls.py b/backend/product/urls.py index e395827..76c6fd8 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -6,6 +6,6 @@ urlpatterns = [ path('categories', AllCategories.as_view(), name='all-categories'), path('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'), path('comments/', CommentView.as_view(), name='comment-views'), - re_path(r'^(?P[\u0600-\u06FF\s]+)/$', ProductView.as_view(), name='product-detail'), + re_path(r'^(?P[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'), path('', AllProductsView.as_view(), name='category-products'), ] \ No newline at end of file From 5ed006ff49e22b35c153743eaf3a1253e56b7626 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 14:11:33 +0330 Subject: [PATCH 2/5] update comment url with slug --- backend/product/urls.py | 4 ++-- backend/product/views.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/product/urls.py b/backend/product/urls.py index 76c6fd8..95b4c21 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -5,7 +5,7 @@ urlpatterns = [ path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-categories'), path('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'), - path('comments/', CommentView.as_view(), name='comment-views'), - re_path(r'^(?P[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'), + 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'), path('', AllProductsView.as_view(), name='category-products'), ] \ No newline at end of file diff --git a/backend/product/views.py b/backend/product/views.py index 1a17238..95c8f24 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -413,17 +413,17 @@ class CommentView(APIView): 404: OpenApiTypes.OBJECT, }, ) - def get(self, request, pk): - product = get_object_or_404(ProductModel, id=pk) + def get(self, request, slug): + product = get_object_or_404(ProductModel, slug=slug) comments = product.comments.filter(review_status__in=['not_reviwed', 'reviewed_and_confirmed']) paginator = self.pagination_class() paginated_comments = paginator.paginate_queryset(comments, request) comments_ser = self.serializer_class(instance=paginated_comments, many=True) return paginator.get_paginated_response(comments_ser.data) - def post(self, request, pk): + def post(self, request, slug): comment_ser = CommentSerializer(data=request.data) - product = get_object_or_404(ProductModel, id=pk) + product = get_object_or_404(ProductModel, slug=slug) if comment_ser.is_valid(): comment_ser.save(product=product, user=request.user) return Response(comment_ser.data, status=status.HTTP_201_CREATED) From ffce23faaff59c7f4f79b86a32b5045be22178b0 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 14:17:32 +0330 Subject: [PATCH 3/5] add slash again --- backend/product/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/product/urls.py b/backend/product/urls.py index 95b4c21..8fb0ad2 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -5,7 +5,7 @@ urlpatterns = [ path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-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'), + 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'), path('', AllProductsView.as_view(), name='category-products'), ] \ No newline at end of file From cd1511892177bf183da2aa26123853e8e57b01a8 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 14:23:54 +0330 Subject: [PATCH 4/5] fix chat route --- backend/chat/urls.py | 4 ++-- backend/chat/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/chat/urls.py b/backend/chat/urls.py index 31c977a..94b9883 100644 --- a/backend/chat/urls.py +++ b/backend/chat/urls.py @@ -1,6 +1,6 @@ -from django.urls import path +from django.urls import path, re_path from . import views urlpatterns = [ - path('product/', views.ProductChatView.as_view(), name='product-chat-view'), + re_path(r'^product/(?P[\w\u0600-\u06FF\-]+)$', views.ProductChatView.as_view(), name='product-chat-view'), ] \ No newline at end of file diff --git a/backend/chat/views.py b/backend/chat/views.py index e677e5a..b806031 100644 --- a/backend/chat/views.py +++ b/backend/chat/views.py @@ -94,12 +94,12 @@ class ProductChatView(APIView): permission_classes = [IsAuthenticated] pagination_class = StructurePagination - def get(self, request, pk): + def get(self, request, slug): """ Retrieve all messages for a product chat. """ user = request.user - product = get_object_or_404(ProductModel, id=pk) + product = get_object_or_404(ProductModel, slug=slug) chat, created = ProductChatModel.objects.get_or_create(user=user, product=product) client = openai.OpenAI(api_key=settings.OPENAI_API_KEY) From 0e4a28aafdb4515cf22b8445a40087b723fc07f6 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 14:27:52 +0330 Subject: [PATCH 5/5] remoce comment slash --- backend/product/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/product/urls.py b/backend/product/urls.py index 8fb0ad2..be2c63a 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -5,7 +5,7 @@ urlpatterns = [ path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-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'^comments/(?P[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'), re_path(r'^(?P[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'), path('', AllProductsView.as_view(), name='category-products'), ] \ No newline at end of file