Skip to content

Commit

Permalink
Merge pull request #122 from null-open-security-community/applied_job…
Browse files Browse the repository at this point in the history
…s_patch

Applied Jobs API
  • Loading branch information
hims1911 authored Jun 14, 2024
2 parents a093901 + 618eac9 commit ec0a95b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_tokens_for_user(user):
return {
"refresh": str(refresh),
"access": str(refresh.access_token),
"user_type": user.user_type
}

@staticmethod
Expand Down
22 changes: 22 additions & 0 deletions apps/applicants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,25 @@ class ApplyToJobSerializer(serializers.Serializer):
class UpdateApplicationStatusSerializer(serializers.Serializer):
application_id = serializers.CharField(required=True)
status = serializers.ChoiceField(choices=constants.STATUS_CHOICES, required=True)






class AppliedJobSerializer(serializers.ModelSerializer):
job = JobSerializer(read_only=True)

class Meta:
model = Applicants
fields = [
'id',
'job',
'created_at',
'updated_at',
'is_deleted',
'is_active',
'status'
]


3 changes: 2 additions & 1 deletion apps/applicants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from apps.applicants.views import (
AllApplicantsOfCompany,
ApplyToJob,
UpdateApplicationStatus,
UpdateApplicationStatus, GetAppliedJobs,
)

urlpatterns = [
path("applicants/", AllApplicantsOfCompany.as_view(), name="applicants"),
path("applied_jobs/",GetAppliedJobs.as_view(), name="applied_jobs"),
path("apply/job", ApplyToJob.as_view(), name="applytojob"),
path(
"application/updatestatus",
Expand Down
41 changes: 39 additions & 2 deletions apps/applicants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from apps.applicants.serializers import (
ApplicantModelSerializer,
ApplyToJobSerializer,
UpdateApplicationStatusSerializer,
UpdateApplicationStatusSerializer, AppliedJobSerializer,
)
from apps.jobs.models import Job
from apps.userprofile.models import UserProfile
Expand Down Expand Up @@ -71,11 +71,48 @@ def post(self, request):
serializer.is_valid(raise_exception=True)

if not Applicants.objects.filter(id=serializer.data["application_id"]).update(
status=serializer.data["status"]
status=serializer.data["status"]
):
raise exceptions.NotFound()

return Response(
{"msg": "Success", "detail": "Status updated successfully."},
status=status.HTTP_200_OK,
)


class GetAppliedJobs(APIView):
"""
get applied jobs will return all the applied jobs associated with that candidate
"""
permission_classes = [permissions.IsAuthenticated, IsProfileCompleted]

@extend_schema(
responses={200: ApplicantModelSerializer(many=True)},
tags=["applied_jobs"]
)
def get(self, request):
"""List all users that belong to the company, or a specific applicant by ID"""
job_id = request.query_params.get('job_id')

# finding out the user_id associated with logged in user_id
user_id = UserProfile.objects.get(user_id=request.user.id)

if job_id:
try:
applicant = Applicants.objects.get(user_id=user_id, job_id=job_id)
return Response(
AppliedJobSerializer(applicant).data,
status=status.HTTP_200_OK
)
except Applicants.DoesNotExist:
return Response(
{"detail": "Applicant not found."},
status=status.HTTP_404_NOT_FOUND
)
else:
applicants = Applicants.objects.filter(user_id=user_id).order_by('-created_at')
return Response(
AppliedJobSerializer(applicants, many=True).data,
status=status.HTTP_200_OK
)

0 comments on commit ec0a95b

Please sign in to comment.