Skip to content
Snippets Groups Projects
Commit 4945987b authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-161: Working on updating guest search

parent cbf359d4
No related branches found
No related tags found
1 merge request!228GREG-161: Search birthdate and name
...@@ -28,7 +28,10 @@ function FrontPage() { ...@@ -28,7 +28,10 @@ function FrontPage() {
const getGuests = (event: React.ChangeEvent<HTMLInputElement>) => { const getGuests = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.value) { if (event.target.value) {
setSearchHasInput(true) setSearchHasInput(true)
fetch(`/api/ui/v1/person/search/${event.target.value}`, fetchJsonOpts()) fetch(
`/api/ui/v1/person/search/?q=${event.target.value}`,
fetchJsonOpts()
)
.then((response) => { .then((response) => {
if (response.ok) { if (response.ok) {
return response.json() return response.json()
......
...@@ -36,10 +36,7 @@ urlpatterns += [ ...@@ -36,10 +36,7 @@ urlpatterns += [
name="invite-resend", name="invite-resend",
), ),
path("invite/", InvitationView.as_view(), name="invitation"), path("invite/", InvitationView.as_view(), name="invitation"),
re_path( path("person/search/", PersonSearchViewSet.as_view({"get": "list"}), name="person-search",
r"person/search/(?P<searchstring>\S+)", # search for sequence of any non-whitespace char ),
PersonSearchViewSet.as_view({"get": "list"}),
name="person-search",
),
path("userinfo/", UserInfoView.as_view(), name="userinfo"), path("userinfo/", UserInfoView.as_view(), name="userinfo"),
] ]
...@@ -4,6 +4,8 @@ from rest_framework.permissions import IsAuthenticated ...@@ -4,6 +4,8 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet from rest_framework.viewsets import GenericViewSet
from greg.api.serializers.person import PersonSearchSerializer, SpecialPersonSerializer from greg.api.serializers.person import PersonSearchSerializer, SpecialPersonSerializer
from rest_framework.response import Response
from rest_framework import status
from greg.models import Identity, Person from greg.models import Identity, Person
from greg.permissions import IsSponsor from greg.permissions import IsSponsor
from gregui import validation from gregui import validation
...@@ -45,7 +47,18 @@ class PersonSearchViewSet(mixins.ListModelMixin, GenericViewSet): ...@@ -45,7 +47,18 @@ class PersonSearchViewSet(mixins.ListModelMixin, GenericViewSet):
serializer_class = PersonSearchSerializer serializer_class = PersonSearchSerializer
def get_queryset(self): def get_queryset(self):
search = self.kwargs["searchstring"] if "q" not in self.request.query_params:
return Response(status=status.HTTP_400_BAD_REQUEST)
search = self.request.query_params["q"]
# TODO Implement search
split_search = search.split()
name_matches = Person.objects.filter(first_name__icontains=search,
last_name__icontains=search)
return Identity.objects.filter( return Identity.objects.filter(
value__icontains=search, # icontains to include wrong case emails value__icontains=search, # icontains to include wrong case emails
type__in=[ type__in=[
......
import pytest
from rest_framework import status
from rest_framework.reverse import reverse
@pytest.mark.django_db
def test_name_search(client, log_in, user_sponsor, create_person):
person = create_person(
first_name="foo",
last_name="bar",
email="foo@bar.com",
)
url = reverse("gregui-v1:person-search", kwargs={"searchstring": "foo bar"})
log_in(user_sponsor)
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
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