-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/pdct 654 return empty 200 on all search entities when no resu…
…lts foun (#54) * PDCT-654 Replaced 404 when no matching docs found with log statement and 200 response. * PDCT-654 Replaced 404 when no matching colls found with log and 200 response. * PDCT-654 Moved query param logic into separate file. * PDCT-654 Updated family search to use query_param.py functions. * PDCT-654 Set default search params & remove duplicate params in default setter. * PDCT-654 Renamed variable to 'default_search_fields', * PDCT-654 Return empty 200 when no collections found during search. * PDCT-654 Return empty 200 when no documents found during search. * PDCT-654 Return empty 200 when no events found during search. * PDCT-654 Updated docstrings with correct DTOs and param descriptions. * PDCT-654 Refactored logic to remove unnecessary code. * PDCT-654 Changed 'description' family search param to 'summary' to match DTO.
- Loading branch information
1 parent
6c9562a
commit 30bf41e
Showing
33 changed files
with
768 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Union, cast | ||
|
||
from fastapi import HTTPException, status | ||
|
||
|
||
def get_query_params_as_dict(query_params) -> dict[str, Union[str, int]]: | ||
print(query_params) | ||
return {k: query_params[k] for k in query_params.keys()} | ||
|
||
|
||
def set_default_query_params( | ||
query_params, | ||
default_query_term: str = "", | ||
default_max_results: int = 500, | ||
) -> dict[str, Union[str, int]]: | ||
query_fields = query_params.keys() | ||
|
||
if len(query_fields) < 1: | ||
return {"q": default_query_term, "max_results": default_max_results} | ||
|
||
if "max_results" not in query_fields: | ||
query_params["max_results"] = default_max_results | ||
|
||
return query_params | ||
|
||
|
||
def validate_query_params( | ||
query_params, valid_params: list[str] = ["q", "max_results"] | ||
) -> bool: | ||
query_fields = query_params.keys() | ||
invalid_params = [x for x in query_fields if x not in valid_params] | ||
if any(invalid_params): | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail=f"Search parameters are invalid: {invalid_params}", | ||
) | ||
|
||
if not isinstance(query_params["max_results"], int): | ||
try: | ||
query_params.update({"max_results": cast(int, query_params["max_results"])}) | ||
except Exception: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="Maximum results must be an integer value", | ||
) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.