Skip to content

Commit

Permalink
Merge pull request #406 from PROCOLLAB-github/feature/flexivanov237-p…
Browse files Browse the repository at this point in the history
…ro-356

added vacancy responses for logged user
  • Loading branch information
sh1nkey authored Jul 25, 2024
2 parents 979c18a + b6131b8 commit 2f42b4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions vacancy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
VacancyResponseDetail,
VacancyResponseAccept,
VacancyResponseDecline,
UserVacancyResponses,
)

app_name = "vacancies"
Expand All @@ -17,6 +18,7 @@
path("<int:pk>/", VacancyDetail.as_view()),
path("<int:vacancy_id>/responses/", VacancyResponseList.as_view()),
path("responses/<int:pk>/", VacancyResponseDetail.as_view()),
path("responses/self", UserVacancyResponses.as_view()),
path("responses/<int:pk>/accept/", VacancyResponseAccept.as_view()),
path("responses/<int:pk>/decline/", VacancyResponseDecline.as_view()),
]
20 changes: 18 additions & 2 deletions vacancy/views.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
)

0 comments on commit 2f42b4c

Please sign in to comment.