From b6131b8adf99cc77393b121039bfda602a449b25 Mon Sep 17 00:00:00 2001 From: Alexey Kudelko Date: Fri, 26 Jul 2024 03:50:45 +1000 Subject: [PATCH] added vacancy responses for logged user --- vacancy/urls.py | 2 ++ vacancy/views.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/vacancy/urls.py b/vacancy/urls.py index b0c66f5a..aa46cd4d 100644 --- a/vacancy/urls.py +++ b/vacancy/urls.py @@ -8,6 +8,7 @@ VacancyResponseDetail, VacancyResponseAccept, VacancyResponseDecline, + UserVacancyResponses, ) app_name = "vacancies" @@ -17,6 +18,7 @@ path("/", VacancyDetail.as_view()), path("/responses/", VacancyResponseList.as_view()), path("responses//", VacancyResponseDetail.as_view()), + path("responses/self", UserVacancyResponses.as_view()), path("responses//accept/", VacancyResponseAccept.as_view()), path("responses//decline/", VacancyResponseDecline.as_view()), ] diff --git a/vacancy/views.py b/vacancy/views.py index e0c8e357..92183ee7 100644 --- a/vacancy/views.py +++ b/vacancy/views.py @@ -1,9 +1,10 @@ +from django.db.models import QuerySet from django_filters import rest_framework as filters from django.shortcuts import get_object_or_404 from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema from rest_framework import generics, mixins, permissions, status -from rest_framework.generics import GenericAPIView +from rest_framework.generics import GenericAPIView, ListAPIView from rest_framework.response import Response @@ -86,7 +87,9 @@ def get_queryset(self): def post(self, request, vacancy_id): vacancy = get_object_or_404(Vacancy, pk=vacancy_id) if not vacancy.is_active: - return Response("You cannot apply for a closed vacancy", status.HTTP_400_BAD_REQUEST) + return Response( + "You cannot apply for a closed vacancy", status.HTTP_400_BAD_REQUEST + ) try: request.data["user_id"] = self.request.user.id @@ -200,3 +203,16 @@ def post(self, request, pk): ) return Response(status=status.HTTP_200_OK) + + +class UserVacancyResponses(ListAPIView): + serializer_class = VacancyResponseListSerializer + permission_classes = [IsVacancyResponseOwnerOrReadOnly] + pagination_class = VacancyPagination + + def get_queryset(self) -> QuerySet[VacancyResponse]: + return ( + VacancyResponse.objects.get_vacancy_response_for_list_view() + .filter(user=self.request.user) + .order_by("datetime_created") + )