|
11 | 11 | ProductSerializer,
|
12 | 12 | ParticularProductSerializer,
|
13 | 13 | ProductImageSerializer,
|
14 |
| - ProductImageCreateSerializer, |
| 14 | + ProductImageCRUDSerializer, |
15 | 15 | ReviewRatingSerializer,
|
16 | 16 | ReviewRatingCreateSerializer
|
17 | 17 | )
|
@@ -54,10 +54,31 @@ def create(self, request, *args, **kwargs):
|
54 | 54 | class ProductImageCreateView(CreateAPIView):
|
55 | 55 | queryset = ProductImage.objects.all()
|
56 | 56 | permission_classes = [IsAuthenticated, IsArtist]
|
57 |
| - serializer_class = ProductImageCreateSerializer |
| 57 | + serializer_class = ProductImageCRUDSerializer |
58 | 58 | parser_classes = [FormParser, MultiPartParser]
|
59 | 59 |
|
60 | 60 |
|
| 61 | +class ProductImageDeleteView(APIView): |
| 62 | + permission_classes = [IsAuthenticated, IsArtist] |
| 63 | + serializer_class = ProductImageCRUDSerializer |
| 64 | + parser_classes = [JSONParser] |
| 65 | + |
| 66 | + def delete(self, request, pi_id): |
| 67 | + user = request.user.id |
| 68 | + try: |
| 69 | + obj = ProductImage.objects.get(id=pi_id, product__artist=user) |
| 70 | + obj.delete() |
| 71 | + return Response({ |
| 72 | + 'status': 'success', |
| 73 | + 'details': 'Successfully deleted product image.' |
| 74 | + }, status=200) |
| 75 | + except: |
| 76 | + return Response({ |
| 77 | + 'status': 'error', |
| 78 | + 'details': 'Error in deleting product image.' |
| 79 | + }, status=400) |
| 80 | + |
| 81 | + |
61 | 82 | class CategoryUpdateDeleteView(RetrieveUpdateDestroyAPIView):
|
62 | 83 | serializer_class = CategorySerializer
|
63 | 84 | parser_classes = [JSONParser]
|
|
0 commit comments