Skip to content

Commit

Permalink
modified logic to handle URL path extensions: prioritize path extensi…
Browse files Browse the repository at this point in the history
…on over query parameter
  • Loading branch information
feba-rajan committed Aug 13, 2024
1 parent 499bcc8 commit 385b62d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions application/routers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,20 @@ def search_entities(
extension: Optional[SuffixEntity] = None,
session: Session = Depends(get_session),
):

# Determine if we should use the query parameter or the path parameter extension
if request.query_params.get("extension"):
extension = None
path_extension = None
if "." in request.url.path:
path_extension = request.url.path.split(".")[-1]

# Determine the final extension to use
if path_extension:
final_extension = SuffixEntity(path_extension)
else:
extension = extension
if request.query_params.get("extension"):
final_extension = None
else:
final_extension = extension

# get query_filters as a dict
query_params = asdict(query_filters)
Expand All @@ -286,7 +295,7 @@ def search_entities(
query = request.url.query
links = make_links(scheme, netloc, path, query, data)

if extension is not None and extension.value == "json":
if final_extension is not None and final_extension.value == "json":
if params.get("field") is not None:
include = set([to_snake(field) for field in params.get("field")])
entities = _get_entity_json(data["entities"], include=include)
Expand All @@ -302,7 +311,7 @@ def search_entities(
entities = _get_entity_json(data["entities"])
return {"entities": entities, "links": links, "count": data["count"]}

if extension is not None and extension.value == "geojson":
if final_extension is not None and final_extension.value == "geojson":
if params.get("exclude_field") is not None:
exclude_fields = set(
[
Expand Down

0 comments on commit 385b62d

Please sign in to comment.