add: add invalid product update api
This commit is contained in:
@@ -82,4 +82,13 @@ class InvliadProductListSerializer(serializers.ModelSerializer):
|
|||||||
return {
|
return {
|
||||||
'id': obj.wherehouse.id,
|
'id': obj.wherehouse.id,
|
||||||
'name': obj.wherehouse.name
|
'name': obj.wherehouse.name
|
||||||
} if obj.wherehouse else None
|
} if obj.wherehouse else None
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidProductUpdateSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = InvalidProduct
|
||||||
|
fields = [
|
||||||
|
'project_folder', 'witnesses', 'work', 'amount', 'invalid_status', 'status',
|
||||||
|
'created_date', 'expiry_date', 'comment', 'file'
|
||||||
|
]
|
||||||
@@ -24,6 +24,7 @@ urlpatterns = [
|
|||||||
[
|
[
|
||||||
path('create/', invalid_product_views.InvalidProductCreateApiView.as_view()),
|
path('create/', invalid_product_views.InvalidProductCreateApiView.as_view()),
|
||||||
path('list/', invalid_product_views.InvalidProductListApiView.as_view()),
|
path('list/', invalid_product_views.InvalidProductListApiView.as_view()),
|
||||||
|
path('<uuid:id>/update/', invalid_product_views.InvalidProductUpdateApiView.as_view()),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from rest_framework import generics, parsers
|
from rest_framework import generics, parsers
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@@ -42,4 +44,26 @@ class InvalidProductListApiView(generics.GenericAPIView):
|
|||||||
serializer = self.serializer_class(page, many=True)
|
serializer = self.serializer_class(page, many=True)
|
||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
serializer = self.serializer_class(invalid_products, many=True)
|
serializer = self.serializer_class(invalid_products, many=True)
|
||||||
return Response(serializer.data, status=200)
|
return Response(serializer.data, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidProductUpdateApiView(generics.GenericAPIView):
|
||||||
|
serializer_class = serializers.InvalidProductUpdateSerializer
|
||||||
|
queryset = InvalidProduct.objects.all()
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
required_permissions = []
|
||||||
|
parser_classes = [parsers.FormParser, parsers.MultiPartParser]
|
||||||
|
|
||||||
|
def patch(self, request, id):
|
||||||
|
invalid_product = get_object_or_404(InvalidProduct, id=id)
|
||||||
|
serializer = self.serializer_class(data=request.data, instance=invalid_product)
|
||||||
|
if serializer.is_valid(raise_exception=True):
|
||||||
|
serializer.save()
|
||||||
|
return Response(
|
||||||
|
{'success': True, 'message': 'updated'},
|
||||||
|
status=200
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
{'success': False, 'error_message': serializer.errors},
|
||||||
|
status=400
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user