Merge branch 'main' of https://github.com/Byeto-Company/hossein_por_shop
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('product/<int:pk>', views.ProductChatView.as_view(), name='product-chat-view'),
|
||||
re_path(r'^product/(?P<slug>[\w\u0600-\u06FF\-]+)$', views.ProductChatView.as_view(), name='product-chat-view'),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -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/<int:pk>', CommentView.as_view(), name='comment-views'),
|
||||
re_path(r'^(?P<slug>[\u0600-\u06FF\s]+)/$', ProductView.as_view(), name='product-detail'),
|
||||
re_path(r'^comments/(?P<slug>[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'),
|
||||
re_path(r'^(?P<slug>[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'),
|
||||
path('', AllProductsView.as_view(), name='category-products'),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user