Corp/backend/api/v1/urls.py
igor_nadein 735babbd46 feat: Add frontend integration for watson search API
Backend:
- Created REST API endpoint /api/v1/search/
- Added SearchResultSerializer and SearchResponseSerializer
- Implemented search_api_view with model formatters (employee, department, post, request, chat, message, event)
- Registered search endpoint in api/v1/urls.py
- Added permission check for requests (HR can see all, users only their own)

Frontend:
- Added SearchResponse, SearchResult, SearchModelType types
- Added apiClient.search() method in lib/api.ts
- Completely rewrote search/page.tsx:
  * Single API call instead of 6 parallel requests
  * Cleaner UI with icons for each result type
  * Real-time search with loading states
  * Meta information display (email, phone, status, etc.)
  * Better performance and UX

Benefits:
- Frontend: 220 lines → 178 lines (19% reduction)
- 1 API request instead of 6 (83% less network calls)
- Server-side full-text search via watson (better relevance)
- Unified search results with metadata

Testing:
- API endpoint verified at /api/v1/search/?q=test
- Returns JSON with query, results, counts, total
- Requires authentication (IsAuthenticated decorator)
2026-02-27 18:27:36 +03:00

92 lines
3.1 KiB
Python

from django.urls import include, path
from rest_framework.routers import DefaultRouter
# django-scheduler ViewSets (проверенная библиотека для календаря)
from .schedule.views import (
ScheduleCalendarViewSet,
ScheduleEventViewSet,
ScheduleRuleViewSet,
ScheduleOccurrenceViewSet,
ScheduleEventRelationViewSet,
)
# Communications ViewSets
from .communications.views import ChatViewSet, MessageViewSet, PollViewSet
from .documents.views import DocumentViewSet
from .employees.views import (
DepartmentRoleViewSet,
DepartmentViewSet,
EmployeeActionViewSet,
EmployeeViewSet,
GroupViewSet,
PositionViewSet,
RegisterAPIView,
ResendEmailAPIView,
SkillViewSet,
VerifyEmailAPIView,
)
from .feed.views import CommentViewSet, PostViewSet
from .requests_app.views import RequestViewSet
from .search.views import search_api_view
app_name = "v1"
router = DefaultRouter()
# django-scheduler endpoints (проверенная библиотека)
router.register(r"schedule/calendars", ScheduleCalendarViewSet, basename="schedule-calendars")
router.register(r"schedule/events", ScheduleEventViewSet, basename="schedule-events")
router.register(r"schedule/rules", ScheduleRuleViewSet, basename="schedule-rules")
router.register(r"schedule/occurrences", ScheduleOccurrenceViewSet, basename="schedule-occurrences")
router.register(r"schedule/relations", ScheduleEventRelationViewSet, basename="schedule-relations")
router.register(r"documents", DocumentViewSet, basename="documents")
router.register(r"requests", RequestViewSet, basename="request")
router.register(r"departments", DepartmentViewSet, basename="departments")
router.register(r"employees", EmployeeViewSet, basename="employees")
router.register(
r"employee-actions",
EmployeeActionViewSet,
basename="employee-actions",
)
router.register(r"positions", PositionViewSet, basename="positions")
router.register(
r"department-roles",
DepartmentRoleViewSet,
basename="department-roles",
)
router.register(r"skills", SkillViewSet, basename="skills")
router.register(r"posts", PostViewSet, basename="posts")
router.register(r"comments", CommentViewSet, basename="comments")
router.register(r"groups", GroupViewSet, basename="groups")
# NEW: Communications ViewSets
router.register(r"communications/chats", ChatViewSet, basename="chats")
router.register(r"communications/messages", MessageViewSet, basename="messages")
router.register(r"communications/polls", PollViewSet, basename="polls")
urlpatterns = [
path("auth/register/", RegisterAPIView.as_view(), name="register"),
path(
"auth/resend-email/",
ResendEmailAPIView.as_view(),
name="resend-email",
),
path(
"auth/verify-email/",
VerifyEmailAPIView.as_view(),
name="verify-email",
),
# Notifications API
path("notifications/", include("api.v1.notifications.urls")),
# Procurement API
path("procurement/", include("api.v1.procurement.urls")),
# Search API
path("search/", search_api_view, name="search"),
# Router URLs (включая все ViewSets)
path("", include(router.urls)),
]