Skip to content
Snippets Groups Projects
Commit d0823fd5 authored by pka065's avatar pka065
Browse files

GREG-292: search for person via v1-api

Add a possibility to search via v1-api, and add birth date to the data in such a case. No changes for previous gui-endpoint.
parent bdcd09d5
No related branches found
No related tags found
1 merge request!348GREG-292: search for person via v1-api
Pipeline #159133 failed
...@@ -17,6 +17,7 @@ from greg.api.views.sponsor import ( ...@@ -17,6 +17,7 @@ from greg.api.views.sponsor import (
SponsorGuestsViewSet, SponsorGuestsViewSet,
SponsorOrgunitLinkView, SponsorOrgunitLinkView,
) )
from gregui.api.views.person import PersonSearchViewSet
router = DefaultRouter(trailing_slash=False) router = DefaultRouter(trailing_slash=False)
router.register(r"persons", PersonViewSet, basename="person") router.register(r"persons", PersonViewSet, basename="person")
...@@ -74,4 +75,9 @@ urlpatterns += [ ...@@ -74,4 +75,9 @@ urlpatterns += [
SponsorOrgunitLinkView.as_view({"post": "create", "delete": "destroy"}), SponsorOrgunitLinkView.as_view({"post": "create", "delete": "destroy"}),
name="sponsor_orgunit-detail", name="sponsor_orgunit-detail",
), ),
re_path(
"person_search/",
PersonSearchViewSet.as_view({"get": "list"}),
name="person-search",
),
] ]
...@@ -107,6 +107,9 @@ class PersonSearchViewSet(GenericViewSet): ...@@ -107,6 +107,9 @@ class PersonSearchViewSet(GenericViewSet):
def get_hits(self): def get_hits(self):
search = self.request.query_params["q"] search = self.request.query_params["q"]
include_birth_date = False
if not "gregui" in self.request.version:
include_birth_date = True
split_search = search.split() split_search = search.split()
words_joined = "|".join(map(str, split_search)) words_joined = "|".join(map(str, split_search))
...@@ -124,9 +127,10 @@ class PersonSearchViewSet(GenericViewSet): ...@@ -124,9 +127,10 @@ class PersonSearchViewSet(GenericViewSet):
included_persons = [] included_persons = []
for person in persons: for person in persons:
hits.append( output_data = {"pid": person.id, "first": person.first_name, "last": person.last_name}
{"pid": person.id, "first": person.first_name, "last": person.last_name} if include_birth_date:
) output_data["date_of_birth"] = person.date_of_birth
hits.append(output_data)
included_persons.append(person.id) included_persons.append(person.id)
if len(hits) == 10: if len(hits) == 10:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment