From c2f28bf713f6fd93d8f028f2aba86eadb7ffb5bc Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 17 Apr 2024 13:18:26 -0300 Subject: [PATCH] fix: return empty results when needed --- bd_api/apps/api/v1/search_views.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bd_api/apps/api/v1/search_views.py b/bd_api/apps/api/v1/search_views.py index 3f9b2553..62c99bd9 100644 --- a/bd_api/apps/api/v1/search_views.py +++ b/bd_api/apps/api/v1/search_views.py @@ -76,17 +76,16 @@ def get_form_kwargs(self): return kwargs def get(self, request, *args, **kwargs): - if form := self.get_form(): - if sqs := form.search(): - return JsonResponse( - { - "count": sqs.count(), - "page": self.page, - "page_size": self.page_size, - "results": self.get_results(sqs), - "aggregations": self.get_facets(sqs), - } - ) + sqs = self.get_form().search() + return JsonResponse( + { + "page": self.page, + "page_size": self.page_size, + "count": sqs.count(), + "results": self.get_results(sqs), + "aggregations": self.get_facets(sqs), + } + ) def get_facets(self, sqs: SearchQuerySet): facets = {}