Skip to content

Commit 88a6faf

Browse files
author
ExpDev07
committed
fixed querying of all properties
1 parent 304de58 commit 88a6faf

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

app/main.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,30 @@ def get_locations(
114114
request: fastapi.Request,
115115
source: Sources = 'jhu',
116116
country_code: str = None,
117+
province: str = None,
118+
county: str = None,
117119
timelines: bool = False,
118120
):
119121
"""
120122
Getting the locations.
121123
"""
124+
# All query paramameters.
125+
params = dict(request.query_params)
126+
122127
# Retrieve all the locations.
123128
locations = request.state.source.get_all()
124129

125-
# Filtering my country code if provided.
126-
if country_code:
127-
locations = list(
128-
filter(
129-
lambda location: location.country_code == country_code.upper(), locations,
130-
)
131-
)
130+
# Attempt to filter out locations with properties matching the provided query params.
131+
for key, value in params.items():
132+
# Clean keys for security purposes.
133+
key = key.lower()
134+
value = value.lower().strip('__')
135+
136+
# Do filtering.
137+
try:
138+
locations = [location for location in locations if str(getattr(location, key)).lower() == str(value)]
139+
except AttributeError:
140+
pass
132141

133142
# Return final serialized data.
134143
return {

0 commit comments

Comments
 (0)