def post(self, request): request_data = get_request_data(request, 'post') cart_id = request_data["cart"] if request_data.get("cart") else None buyer = Buyer.get_active_objects(id=request.user.id) if buyer.exists(): cart = Cart.get_active_objects(buyer_id=buyer[0].id) if str(cart_id) == str(cart[0].id): serializer = self.write_serializer_class(data=request_data) if serializer.is_valid(): order = serializer.save() data = self.detail_serializer_class(order).data return response(data, status.HTTP_201_CREATED) return inv_serializer_error_response(serializer, status.HTTP_400_BAD_REQUEST) return error_response(CONST_ERROR_MESSAGE_PERMISSION_DENIED_KEY, status.HTTP_400_BAD_REQUEST) return error_response(CONST_ERROR_MESSAGE_INVALID_USER_KEY, status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk): request_data = get_request_data(request, 'delete') queryset, serializer_class = self.get_queryset(pk) if queryset.exists(): timestamp = now() instance = queryset[0] cart_id = instance.cart_id buyer = Buyer.get_active_objects(id=request.user.id) if buyer.exists(): cart = Cart.get_active_objects(buyer_id=buyer[0].id) if str(cart_id) == str(cart[0].id): instance.is_deleted = True instance.deleted_at = timestamp instance.modified_at = timestamp instance.save() return response({'deleted':True}, status.HTTP_200_OK) return error_response(CONST_ERROR_MESSAGE_PERMISSION_DENIED_KEY, status.HTTP_400_BAD_REQUEST) return error_response(CONST_ERROR_MESSAGE_INVALID_USER_KEY, status.HTTP_400_BAD_REQUEST) return error_response(CONST_ERROR_MESSAGE_INVALID_ID_KEY,status.HTTP_400_BAD_REQUEST)