diff --git a/.gitignore b/.gitignore index 932844a06..9717e5a81 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ venv/ "db.sqlite3" venv duovenv/ -env \ No newline at end of file +env +Pipenv.lock \ No newline at end of file diff --git a/deals/urls.py b/deals/urls.py index f28b09287..fb1859217 100644 --- a/deals/urls.py +++ b/deals/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from deals.views import DealCreateView, DealsListView +from deals.views import DealCreateView, DealUpdateView urlpatterns = [ path("create/", DealCreateView.as_view()), - path('list/', DealsListView.as_view(),), + path("update//", DealUpdateView.as_view()), + path('list/', DealsListView.as_view()) ] \ No newline at end of file diff --git a/deals/views.py b/deals/views.py index 8539d8aae..bd54e02ad 100644 --- a/deals/views.py +++ b/deals/views.py @@ -2,7 +2,6 @@ from django.conf import settings from deals.serializers import DealSerializer from rest_framework.views import APIView -from rest_framework import status import requests import json from rest_framework.response import Response @@ -48,9 +47,37 @@ def post(self, request, *args, **kwargs): print(response.status_code) print(r) if response.status_code == 201: - return Response(data={'message':'Created deal object successfully!'}, status=status.HTTP_201_CREATED) + return Response(data={'message':'Created deal object successfully!'}, status=st.HTTP_201_CREATED) return Response(data={"message":"Creation of deals failed... Try again later."}, status=st.HTTP_500_INTERNAL_SERVER_ERROR) +class DealUpdateView(APIView): + """ + An endpoint to update a deal, takes in prospect_id, status, title, and amount. + The endpoint is https://sales.zuri.chat/deals/update// + """ + serializer_class = DealSerializer + queryset = None + + def put(self, request, *args, **kwargs): + url = "https://zccore.herokuapp.com/data/write" + serializer = DealSerializer(data=request.data) + serializer.is_valid(raise_exception=True) + data = { + "plugin_id": "000000000000000000000000", + "organization_id": "612a3a914acf115e685df8e3", + "collection_name": "deals", + "bulk_write": False, + "object_id":serializer.data.get("_id"), + "payload": serializer.data + } + response = requests.request("POST", url,data=json.dumps(data)) + r = response.json() + print(response.status_code) + print(r) + if response.status_code == 201: + return Response(data={'message':'successful'}, status=st.HTTP_201_CREATED) + return Response(data={"message":"Try again later"}, status=st.HTTP_500_INTERNAL_SERVER_ERROR) + class DealsListView(APIView): """ Documentation here. @@ -69,5 +96,6 @@ def get(self, request, *args, **kwargs): if response.status_code == 200: serializer = DealSerializer(data=r['data'], many=True) serializer.is_valid(raise_exception=True) - return Response(data=serializer.data, status=status.HTTP_200_OK) - return Response(data={"message":"Try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file + return Response(data=serializer.data, status=st.HTTP_200_OK) + return Response(data={"message":"Try again later"}, status=st.HTTP_500_INTERNAL_SERVER_ERROR) + diff --git a/prospect/views.py b/prospect/views.py index 63e7f2183..71a9362f0 100644 --- a/prospect/views.py +++ b/prospect/views.py @@ -155,9 +155,9 @@ def put(self, request, *args, **kwargs): "payload": serializer.data } response = requests.request("POST", url,data=json.dumps(data)) + r = response.json() print(response.status_code) print(r) if response.status_code == 201: - r = response.json() return Response(data={'message':'successful'}, status=status.HTTP_201_CREATED) return Response(data={"message":"Try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)