Skip to content

Commit

Permalink
🎨 [#209] improved the way we filter urls in queryparams
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed Aug 15, 2024
1 parent 5268000 commit fc0d5e6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,59 @@
class DigitaalAdresFilterSet(FilterSet):
verstrekt_door_betrokkene__uuid = filters.UUIDFilter(
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van de betrokkene uuid."
"Zoek digitaal adres(sen) object(en) op basis van de betrokkene uuid."
),
field_name="betrokkene__uuid",
)
verstrekt_door_betrokkene__url = filters.CharFilter(
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van de betrokkene url."
"Zoek digitaal adres(sen) object(en) op basis van de betrokkene url."
),
method="filter_betrokkene_url",
)
verstrekt_door_betrokkene__rol = filters.ChoiceFilter(
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van de betrokkene rol."
"Zoek digitaal adres(sen) object(en) op basis van de betrokkene rol."
),
field_name="betrokkene__rol",
)
verstrekt_door_partij__uuid = filters.UUIDFilter(
help_text=_("Zoek digitaal adres(sen) object(s) op basis van de partij uuid."),
help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij uuid."),
field_name="betrokkene__uuid",
)
verstrekt_door_partij__url = filters.CharFilter(
help_text=_("Zoek digitaal adres(sen) object(s) op basis van de partij url."),
help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij url."),
method="filter_partij_url",
)
verstrekt_door_partij__soort_partij = filters.ChoiceFilter(
help_text=_("Zoek digitaal adres(sen) object(s) op basis van de partij soort."),
help_text=_(
"Zoek digitaal adres(sen) object(en) op basis van de partij soort."
),
field_name="partij__soort_partij",
)
adres = filters.CharFilter(
lookup_expr="exact",
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van adres die de exacte waarden bevat."
"Zoek digitaal adres(sen) object(en) op basis van adres dat exact gelijk moet zijn aan deze waarde."
),
)
adres__icontains = filters.CharFilter(
lookup_expr="icontains",
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van adres die de opgegeven waarden bevat."
"Zoek digitaal adres(sen) object(en) op basis van adres die de opgegeven waarden bevat."
),
)
soort_digitaal_adres = filters.CharFilter(
lookup_expr="exact",
help_text=_(
"Zoek digitaal adres(sen) object(en) op basis van het soort digitaal adres "
"dat exact gelijk moet zijn aan deze waarde."
),
)
omschrijving = filters.CharFilter(
lookup_expr="icontains",
help_text=_(
"Zoek digitaal adres(sen) object(s) op basis van omschijving die de opgegeven waarden bevat."
"Zoek digitaal adres(sen) object(en) op basis van omschijving die de opgegeven waarden bevat."
),
)

Expand All @@ -74,14 +83,14 @@ class Meta:

def filter_betrokkene_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(betrokkene__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(partij__uuid=url_uuid)
except ValueError:
return queryset.none()
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class Meta:

def filter_toegewezen_aan_actor_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(actor__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_aanleidinggevend_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ class Meta:

def filter_betrokkene_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(betrokkene__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_onderwerpobject_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(onderwerpobject__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_was_onderwerpobject_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(was_onderwerpobject__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand Down Expand Up @@ -157,7 +157,7 @@ class Meta:

def filter_had_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand All @@ -180,7 +180,7 @@ def filter_digitaaladres_adres(self, queryset, name, value):

def filter_digitaaladres_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(digitaaladres__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand All @@ -197,7 +197,7 @@ def filter_partij_nummer(self, queryset, name, value):

def filter_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(partij__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand Down Expand Up @@ -233,14 +233,14 @@ class Meta:

def filter_actor_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(actor__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Meta:

def filter_vertegenwoordigde_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(
vertegenwoordigde__vertegenwoordigende_partij__uuid=url_uuid
)
Expand Down Expand Up @@ -166,14 +166,14 @@ class Meta:

def filter_vertegenwoordigende_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(vertegenwoordigende_partij__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_vertegenwoordigde_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(vertegenwoordigde_partij__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand Down Expand Up @@ -227,7 +227,7 @@ def filter_partij_uuid(self, queryset, name, value):

def filter_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(partij__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand All @@ -247,7 +247,7 @@ def filter_categorie_uuid(self, queryset, name, value):

def filter_categorie_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.split("/")[-1])
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(categorie__uuid=url_uuid)
except ValueError:
return queryset.none()
Expand Down
56 changes: 11 additions & 45 deletions src/openklant/components/klantinteracties/api/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,7 @@ def setUp(self):
def test_filter_vertegenwoordigde_partij_url(self):
partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}"
response = self.client.get(
self.url,
{"vertegenwoordigdePartij__url": partij_url},
content_type="application/json",
self.url, {"vertegenwoordigdePartij__url": partij_url}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -714,11 +712,7 @@ def setUp(self):

def test_filter_partij_url(self):
partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}"
response = self.client.get(
self.url,
{"partij__url": partij_url},
content_type="application/json",
)
response = self.client.get(self.url, {"partij__url": partij_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down Expand Up @@ -793,11 +787,7 @@ def test_filter_partij_nummer(self):

def test_filter_categorie_url(self):
categorie_url = f"http://testserver/klantinteracties/api/v1/categorieen/{str(self.categorie5.uuid)}"
response = self.client.get(
self.url,
{"categorie__url": categorie_url},
content_type="application/json",
)
response = self.client.get(self.url, {"categorie__url": categorie_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down Expand Up @@ -909,11 +899,7 @@ def setUp(self):

def test_filter_klantcontact_url(self):
klantcontact_url = f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(self.klantcontact5.uuid)}"
response = self.client.get(
self.url,
{"klantcontact__url": klantcontact_url},
content_type="application/json",
)
response = self.client.get(self.url, {"klantcontact__url": klantcontact_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down Expand Up @@ -942,11 +928,7 @@ def test_filter_actor_url(self):
actor_url = (
f"http://testserver/klantinteracties/api/v1/actoren/{str(self.actor5.uuid)}"
)
response = self.client.get(
self.url,
{"actor__url": actor_url},
content_type="application/json",
)
response = self.client.get(self.url, {"actor__url": actor_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down Expand Up @@ -1007,9 +989,7 @@ def setUp(self):
def test_filter_vertegenwoordigende_partij_url(self):
partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}"
response = self.client.get(
self.url,
{"vertegenwoordigendePartij__url": partij_url},
content_type="application/json",
self.url, {"vertegenwoordigendePartij__url": partij_url}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1041,9 +1021,7 @@ def test_filter_vertegenwoordigende_partij_url(self):
def test_filter_vertegenwoordigde_partij_url(self):
partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}"
response = self.client.get(
self.url,
{"vertegenwoordigdePartij__url": partij_url},
content_type="application/json",
self.url, {"vertegenwoordigdePartij__url": partij_url}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1112,11 +1090,7 @@ def test_filter_toegewezen_aan_actor_url(self):
actor_url = (
f"http://testserver/klantinteracties/api/v1/actoren/{str(self.actor5.uuid)}"
)
response = self.client.get(
self.url,
{"toegewezenAanActor__url": actor_url},
content_type="application/json",
)
response = self.client.get(self.url, {"toegewezenAanActor__url": actor_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down Expand Up @@ -1146,9 +1120,7 @@ def test_filter_toegewezen_aan_actor_url(self):
def test_filter_aanleidinggevend_klantcontact_url(self):
klantcontact_url = f"http://testserver/klantinteracties/api/v1/klantcontacten/{str(self.klantcontact5.uuid)}"
response = self.client.get(
self.url,
{"aanleidinggevendKlantcontact__url": klantcontact_url},
content_type="application/json",
self.url, {"aanleidinggevendKlantcontact__url": klantcontact_url}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1214,9 +1186,7 @@ def setUp(self):
def test_filter_verstrekt_door_betrokkene_url(self):
betrokkene_url = f"http://testserver/klantinteracties/api/v1/betrokkenen/{str(self.betrokkene5.uuid)}"
response = self.client.get(
self.url,
{"verstrektDoorBetrokkene__url": betrokkene_url},
content_type="application/json",
self.url, {"verstrektDoorBetrokkene__url": betrokkene_url}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1247,11 +1217,7 @@ def test_filter_verstrekt_door_betrokkene_url(self):

def test_filter_verstrekt_door_partij_url(self):
partij_url = f"http://testserver/klantinteracties/api/v1/partijen/{str(self.partij5.uuid)}"
response = self.client.get(
self.url,
{"verstrektDoorPartij__url": partij_url},
content_type="application/json",
)
response = self.client.get(self.url, {"verstrektDoorPartij__url": partij_url})
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()["results"]
Expand Down
Loading

0 comments on commit fc0d5e6

Please sign in to comment.