feat: LinkedIn profile search engine (Django + React + Elasticsearch + ELK)
Full-stack implementation of the Cyberyan full-stack trial task. Backend (Django 5 / DRF) - Normalised PostgreSQL model (Profile, Company, School, Skill, Experience, Education) as the source of truth, with GIN + trigram indexes. - Self-healing CSV reader: the supplied export carries an injected watermark column, missing columns, rows split by broken quoting and a duplicated header. A signature-scored Needleman-Wunsch alignment reconstructs 284 clean records out of 336 physical rows; only 10 rows parse correctly without it. - Pluggable search layer (Strategy): Elasticsearch by default, PostgreSQL full-text search as a fallback selected by a single environment variable. - Keyword search with per-field boosts, fuzziness and phrase boosting, six faceted filters (OR within a filter, AND across filters), an experience range, four sort orders, highlighting and facet aggregations. - JWT auth with rotation + blacklist, three roles, PII masking, scoped rate limits, a single error envelope, OpenAPI schema and health probes. Frontend (React 18 / TypeScript / Vite) - Debounced search with type-ahead, faceted filter panel, result cards, profile drawer, URL-synced search state, automatic token refresh. - Highlight snippets rendered without dangerouslySetInnerHTML. Infrastructure - Hardened multi-stage images (non-root, read-only rootfs, healthchecks). - docker-compose for the full stack plus dev and production overlays. - ELK: structured JSON logs shipped asynchronously to Logstash, routed per event type, with a composable index template and a Kibana setup script. Quality - 61 backend tests (85% coverage), ruff/black/bandit/mypy, ESLint + tsc, GitHub Actions running lint, tests and both image builds. - Persian documentation: README plus architecture, search, API, data, security and operations guides. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GnFo6fNaHCTAkJbfcdkqtG
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""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]
|
||||
Reference in New Issue
Block a user