Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #199 from paisoncodes/dev
Browse files Browse the repository at this point in the history
Created Deals Update Endpoint
  • Loading branch information
sparkle666 authored Sep 3, 2021
2 parents c556f5a + 7f8b87f commit 01398e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ venv/
"db.sqlite3"
venv
duovenv/
env
env
Pipenv.lock
5 changes: 3 additions & 2 deletions deals/urls.py
Original file line number Diff line number Diff line change
@@ -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/<str:id>/", DealUpdateView.as_view()),
path('list/', DealsListView.as_view())
]
36 changes: 32 additions & 4 deletions deals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/<str:id>/
"""
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.
Expand All @@ -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)
return Response(data=serializer.data, status=st.HTTP_200_OK)
return Response(data={"message":"Try again later"}, status=st.HTTP_500_INTERNAL_SERVER_ERROR)

2 changes: 1 addition & 1 deletion prospect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 01398e3

Please sign in to comment.