add new api
This commit is contained in:
11
core/apps/orders/serializers/supplier.py
Normal file
11
core/apps/orders/serializers/supplier.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from core.apps.orders.models import Supplier
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierListSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Supplier
|
||||||
|
fields = [
|
||||||
|
'id', 'phone', 'full_name', 'tg_id'
|
||||||
|
]
|
||||||
@@ -8,4 +8,5 @@ urlpatterns = [
|
|||||||
path('order/list/', order_views.OrderListApiView.as_view()),
|
path('order/list/', order_views.OrderListApiView.as_view()),
|
||||||
path('supplier/create/', supp_views.SupplierCreateApiView.as_view()),
|
path('supplier/create/', supp_views.SupplierCreateApiView.as_view()),
|
||||||
path('supplier/<str:tg_id>/', supp_views.SupplierGetApiView.as_view()),
|
path('supplier/<str:tg_id>/', supp_views.SupplierGetApiView.as_view()),
|
||||||
|
path('supplier/list/', supp_views.SupplierListApiView.as_view()),
|
||||||
]
|
]
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
from rest_framework import views
|
from rest_framework import views, permissions
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core.apps.orders.models import Supplier
|
from core.apps.orders.models import Supplier
|
||||||
|
from core.apps.orders.serializers.supplier import SupplierListSerializer
|
||||||
|
|
||||||
|
|
||||||
class SupplierCreateApiView(views.APIView):
|
class SupplierCreateApiView(views.APIView):
|
||||||
@@ -25,4 +26,12 @@ class SupplierGetApiView(views.APIView):
|
|||||||
return Response({'success': True}, status=200)
|
return Response({'success': True}, status=200)
|
||||||
else:
|
else:
|
||||||
return Response({"success": False},status=404)
|
return Response({"success": False},status=404)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierListApiView(views.APIView):
|
||||||
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
supp = Supplier.objects.all()
|
||||||
|
serializer = SupplierListSerializer(supp, many=True)
|
||||||
|
return Response(serializer.data, status=200)
|
||||||
Reference in New Issue
Block a user