From 9aa714288f01377bc11a1e1c895fbfee873768ce Mon Sep 17 00:00:00 2001 From: SalmanAsh Date: Tue, 16 Jul 2024 08:37:58 +0000 Subject: [PATCH] Add urls for views --- api/serializers/sign_agreement.py | 4 ++++ api/urls.py | 9 +++++++++ api/views/__init__.py | 2 ++ api/views/check_agreement.py | 15 +++++++++------ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 api/serializers/sign_agreement.py diff --git a/api/serializers/sign_agreement.py b/api/serializers/sign_agreement.py new file mode 100644 index 0000000..889dc72 --- /dev/null +++ b/api/serializers/sign_agreement.py @@ -0,0 +1,4 @@ +""" +© Ocado Group +Created on 16/07/2024 at 09:05:55(+01:00). +""" diff --git a/api/urls.py b/api/urls.py index 13b885f..8d2d8db 100644 --- a/api/urls.py +++ b/api/urls.py @@ -19,6 +19,15 @@ from codeforlife.urls import get_urlpatterns from rest_framework.routers import DefaultRouter +from .views import CheckAgreementViewSet + router = DefaultRouter() +router.register( + "check-agreement", + CheckAgreementViewSet, + basename="CheckAgreementViewSet", +) + + urlpatterns = get_urlpatterns(router.urls) diff --git a/api/views/__init__.py b/api/views/__init__.py index e7f7f62..155391f 100644 --- a/api/views/__init__.py +++ b/api/views/__init__.py @@ -2,3 +2,5 @@ © Ocado Group Created on 02/07/2024 at 11:59:45(+01:00). """ + +from .check_agreement import CheckAgreementViewSet diff --git a/api/views/check_agreement.py b/api/views/check_agreement.py index e25ad5e..1bdabf0 100644 --- a/api/views/check_agreement.py +++ b/api/views/check_agreement.py @@ -6,11 +6,9 @@ from typing import Dict import requests - -# from codeforlife.request import Request +from codeforlife.permissions import AllowAny from codeforlife.response import Response - -# from codeforlife.user.models import User +from codeforlife.user.models import User from codeforlife.views import ModelViewSet # from django.http import HttpResponse @@ -18,8 +16,10 @@ from ..models import AgreementSignature, Contributor +# from rest_framework.views import APIView + -class CheckAgreementViewSet(ModelViewSet): +class CheckAgreementViewSet(ModelViewSet[User, Contributor]): """ An endpoint to check if a contributor has signed latest agreement, return OKAY if he has otherwise return the latest commit ID. @@ -67,4 +67,7 @@ def get(self, request): if latest_commit_id == latest_signature.agreement_id: return Response(status=status.HTTP_200_OK) - return Response(status=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS) + return Response( + data={"latest_commit_id: ": latest_commit_id}, + status=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS, + )