From f3709816c91e5d510178b6f0ed284d6bfc157302 Mon Sep 17 00:00:00 2001 From: Ankur Date: Fri, 19 Jan 2024 13:25:44 +0100 Subject: [PATCH] Read APIs for Applications --- .../serializers/application_serializer.py | 10 ++++++++++ src/involvement/urls.py | 2 +- src/involvement/views/__init__.py | 1 + src/involvement/views/application_api.py | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/involvement/serializers/application_serializer.py create mode 100644 src/involvement/views/application_api.py diff --git a/src/involvement/serializers/application_serializer.py b/src/involvement/serializers/application_serializer.py new file mode 100644 index 00000000..3eac488c --- /dev/null +++ b/src/involvement/serializers/application_serializer.py @@ -0,0 +1,10 @@ +from involvement.models.application import Application +from rest_framework import serializers + +#Role serializer +class ApplicationSerializer(serializers.ModelSerializer): + class Meta: + model = Application + fields = '__all__' + depth = 1 + diff --git a/src/involvement/urls.py b/src/involvement/urls.py index 5b2deffc..b4cd2a19 100644 --- a/src/involvement/urls.py +++ b/src/involvement/urls.py @@ -8,7 +8,7 @@ router.register(r'^position2', views.position_api.Position2ViewSet, basename="Position2View") router.register(r'^teams', views.team_read_api.TeamViewSet, basename="TeamsView") router.register(r'^roles', views.role_read_api.RoleViewSet, basename="RolesView") - +router.register(r'^application', views.application_api.ApplicationViewSet, basename="ApplicationView") urlpatterns = [ re_path( diff --git a/src/involvement/views/__init__.py b/src/involvement/views/__init__.py index 131892ed..bce2a547 100644 --- a/src/involvement/views/__init__.py +++ b/src/involvement/views/__init__.py @@ -18,3 +18,4 @@ from .role_inspect_view import RoleInspectView from .team_read_api import TeamViewSet from .role_read_api import RoleViewSet +from .application_api import ApplicationViewSet diff --git a/src/involvement/views/application_api.py b/src/involvement/views/application_api.py new file mode 100644 index 00000000..90fd2373 --- /dev/null +++ b/src/involvement/views/application_api.py @@ -0,0 +1,14 @@ +from rest_framework import viewsets +from involvement.serializers.application_serializer import ApplicationSerializer +from rest_framework.permissions import IsAuthenticated +from involvement.models.application import Application + +#Role view +class ApplicationViewSet(viewsets.ReadOnlyModelViewSet): + serializer_class = ApplicationSerializer + permission_classes = [IsAuthenticated] + + def get_queryset(self): + user = self.request.user + queryset = Application.objects.filter(applicant=user) + return queryset