73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
|
|
"""Profile read endpoints (the search endpoints live in ``apps.search``)."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from django.db.models import QuerySet
|
||
|
|
from drf_spectacular.utils import extend_schema
|
||
|
|
from rest_framework import generics
|
||
|
|
from rest_framework.permissions import IsAuthenticated
|
||
|
|
|
||
|
|
from apps.profiles.models import Profile, Skill
|
||
|
|
from apps.profiles.serializers import (
|
||
|
|
ProfileDetailSerializer,
|
||
|
|
ProfileListSerializer,
|
||
|
|
SkillSerializer,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@extend_schema(tags=["profiles"])
|
||
|
|
class ProfileListView(generics.ListAPIView):
|
||
|
|
"""
|
||
|
|
Plain, unranked listing.
|
||
|
|
|
||
|
|
Useful for browsing and for verifying the dataset; ranked keyword search is
|
||
|
|
served by ``/api/v1/search/``.
|
||
|
|
"""
|
||
|
|
|
||
|
|
serializer_class = ProfileListSerializer
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
|
||
|
|
def get_queryset(self) -> QuerySet[Profile]:
|
||
|
|
return (
|
||
|
|
Profile.objects.select_related("current_company")
|
||
|
|
.prefetch_related("profile_skills__skill")
|
||
|
|
.order_by("full_name", "id")
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@extend_schema(tags=["profiles"])
|
||
|
|
class ProfileDetailView(generics.RetrieveAPIView):
|
||
|
|
"""Full profile including work history, education and (masked) contacts."""
|
||
|
|
|
||
|
|
serializer_class = ProfileDetailSerializer
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
|
||
|
|
def get_queryset(self) -> QuerySet[Profile]:
|
||
|
|
return Profile.objects.select_related("current_company").prefetch_related(
|
||
|
|
"profile_skills__skill",
|
||
|
|
"experiences__company",
|
||
|
|
"educations__school",
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@extend_schema(tags=["profiles"])
|
||
|
|
class SkillListView(generics.ListAPIView):
|
||
|
|
"""
|
||
|
|
Skill dictionary ordered by popularity.
|
||
|
|
|
||
|
|
The frontend uses it to power the skill filter's type-ahead without hitting
|
||
|
|
Elasticsearch for every keystroke.
|
||
|
|
"""
|
||
|
|
|
||
|
|
serializer_class = SkillSerializer
|
||
|
|
permission_classes = [IsAuthenticated]
|
||
|
|
pagination_class = None
|
||
|
|
|
||
|
|
def get_queryset(self) -> QuerySet[Skill]:
|
||
|
|
queryset = Skill.objects.filter(profile_count__gt=0)
|
||
|
|
term = self.request.query_params.get("q", "").strip().lower()
|
||
|
|
if term:
|
||
|
|
queryset = queryset.filter(name__icontains=term[:64])
|
||
|
|
limit = min(int(self.request.query_params.get("limit", 50) or 50), 200)
|
||
|
|
return queryset.order_by("-profile_count", "name")[:limit]
|