Skip to content

Commit bcf32c2

Browse files
author
ExpDev07
committed
Added filtering by /v2/locations?country_code=XX
1 parent f28c264 commit bcf32c2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/routes/v2/locations.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
@app.route('/v2/locations')
55
def locations():
66
# Query parameters.
7-
country_code = request.args.get('country_code')
7+
country_code = request.args.get('country_code', type=str)
8+
9+
# Retrieve all the locations.
10+
locations = jhu.get_all()
11+
12+
# Filtering my country code if provided.
13+
if not country_code is None:
14+
locations = list(filter(lambda location: location.country_code == country_code.upper(), locations))
815

916
# Serialize each location and return.
1017
return jsonify({
1118
'locations': [
12-
location.serialize() for location in jhu.get_all(country_code=country_code)
19+
location.serialize() for location in locations
1320
]
1421
})
1522

0 commit comments

Comments
 (0)