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

Change name of field with person ID + add serializer for output in swagger

parent 64c870c0
No related branches found
No related tags found
1 merge request!348GREG-292: search for person via v1-api
Pipeline #161344 passed
......@@ -24,3 +24,18 @@ class PersonSerializer(serializers.ModelSerializer):
"roles",
"consents",
]
class PersonSearchSerializer(serializers.ModelSerializer):
person_id = serializers.CharField(source="id")
first = serializers.CharField(source="first_name")
last = serializers.CharField(source="last_name")
class Meta:
model = Person
fields = [
"person_id",
"first",
"last",
"date_of_birth",
]
......@@ -15,6 +15,7 @@ from greg.api.pagination import PrimaryKeyCursorPagination
from greg.api.serializers.consent import ConsentSerializerBrief
from greg.api.serializers.person import (
PersonSerializer,
PersonSearchSerializer,
IdentitySerializer,
)
from greg.api.serializers.role import RoleSerializer, RoleWriteSerializer
......@@ -63,6 +64,7 @@ class PersonSearchSet(viewsets.ModelViewSet):
"""Search for persons using name, email, phone number and birth date"""
permission_classes = (permissions.IsAdminUser,)
serializer_class = PersonSearchSerializer
def list(self, request, *args, **kwargs):
if "q" not in self.request.query_params:
......
......@@ -3,6 +3,10 @@ from greg.models import Identity, Person
def person_by_string_query(request):
search = request.query_params["q"]
if "gregui" in request.version:
id_field_name = "pid"
else:
id_field_name = "person_id"
split_search = search.split()
words_joined = "|".join(map(str, split_search))
......@@ -22,7 +26,7 @@ def person_by_string_query(request):
for person in persons:
hits.append(
{
"pid": person.id,
id_field_name: person.id,
"first": person.first_name,
"last": person.last_name,
"date_of_birth": person.date_of_birth,
......@@ -49,7 +53,7 @@ def person_by_string_query(request):
hits.append(
{
"pid": identity.person_id,
id_field_name: identity.person_id,
"first": identity.person.first_name,
"last": identity.person.last_name,
"value": identity.value,
......
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