add: add api for bot
This commit is contained in:
@@ -18,4 +18,5 @@ urlpatterns = [
|
|||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
path('search/', search_views.SearchApiView.as_view()),
|
path('search/', search_views.SearchApiView.as_view()),
|
||||||
|
path('set_tg_id/<str:code>/', product_views.UpdateProductTgIdApiView.as_view()),
|
||||||
]
|
]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from rest_framework import generics
|
from rest_framework import generics, views
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core.apps.products.models import Product, Category
|
from core.apps.products.models import Product, Category
|
||||||
@@ -46,4 +46,12 @@ class ProductDetailApiView(generics.GenericAPIView):
|
|||||||
def get(self, request, id):
|
def get(self, request, id):
|
||||||
product = get_object_or_404(Product, id=id)
|
product = get_object_or_404(Product, id=id)
|
||||||
serializer = self.serializer_class(product)
|
serializer = self.serializer_class(product)
|
||||||
return Response(serializer.data, status=200)
|
return Response(serializer.data, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateProductTgIdApiView(views.APIView):
|
||||||
|
def post(self, request, product_code):
|
||||||
|
product = get_object_or_404(Product, code=product_code)
|
||||||
|
product.tg_id = request.data.get('tg_id')
|
||||||
|
product.save()
|
||||||
|
return Response({'success': True, 'message': 'telegram id saqlandi'}, status=200)
|
||||||
Reference in New Issue
Block a user