Commit 7dd7acf9 authored by Volkov Gherman's avatar Volkov Gherman

Add api views in api app

parent 836b1c2a
......@@ -3,7 +3,7 @@ from rest_framework import serializers
from api.models import SignerInfo
class DocumentNDASerializer(serializers.ModelSerializer):
class SignerInfoSerializer(serializers.ModelSerializer):
class Meta:
model = SignerInfo
......
......@@ -44,7 +44,7 @@
<script>
const sendForm = (e) => {
e.preventDefault();
fetch(`${window.location.protocol + '//' + window.location.host}/api/v1/`, {
fetch(`${window.location.protocol + '//' + window.location.host}/send_email/`, {
method: 'POST',
body: new FormData(form)
})
......
......@@ -6,7 +6,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from api.models import StatusChoices, SignerInfo
from api.serializers import DocumentNDASerializer
from api.serializers import SignerInfoSerializer
from api.services import send_docusign_email
......@@ -22,7 +22,7 @@ class SendDocumentView(APIView):
return Response(template_name=self.template_name, status=200)
def post(self, request):
serializer = DocumentNDASerializer(data=request.data)
serializer = SignerInfoSerializer(data=request.data)
if serializer.is_valid():
signer = serializer.save()
try:
......@@ -46,3 +46,39 @@ def view_status(request):
else:
data = {'signer': signer, 'status': 'default'}
return render(request, 'status.html', context={'data': data}, status=200)
class SignApiView(APIView):
def get(self, request):
data = {'message': 'Заполните три поля, '
'Для отправки письма на подпись: "signer_name" - Ваше имя, '
'"signer_surmane" - Ваша фамилия, '
'"signer_email" - Ваш email и нажмите кнопку отправить'}
return Response(data=data, status=200)
def post(self, request):
print(request.data, 'data')
serializer = SignerInfoSerializer(data=request.data)
if serializer.is_valid():
signer = serializer.save()
try:
send_docusign_email()
signer.status = StatusChoices.RESOLVE
signer.save()
return Response(status=200, data=serializer.data)
except HTTPException as e:
signer.status = StatusChoices.REJECT
signer.save()
return Response({'error': e, 'signer': signer}, status=503)
return Response({'error': 'Bad Request', 'description': 'Введенные Вами данные не валидны'}, status=400)
class SignApiDetailView(APIView):
def get(self, request, pk):
try:
signer = SignerInfo.objects.get(pk=pk)
serializer = SignerInfoSerializer(signer)
return Response(serializer.data, status=200)
except SignerInfo.DoesNotExist:
return Response({'error': 'Объект не найден'}, status=404)
......@@ -17,12 +17,13 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from api.views import index_view, SendDocumentView, view_status
from api.views import index_view, SendDocumentView, view_status, SignApiView, SignApiDetailView
urlpatterns = [
path('admin/', admin.site.urls),
path('', index_view, name='index'),
path('api/v1/', SendDocumentView.as_view(), name='send_email'),
path('api/v1/status/', view_status, name='view_status'),
path('send_email/', SendDocumentView.as_view(), name='send_email'),
path('status/', view_status, name='view_status'),
path('api/v1/', SignApiView.as_view(), name='send_email'),
path('api/v1/<int:pk>/', SignApiDetailView.as_view(), name='sign_api_retrieve'),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment