File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 44import datetime as dt
55import logging
66import os
7+ import reprlib
78from typing import Dict , List
89
910import fastapi
@@ -46,11 +47,11 @@ class Country(pydantic.BaseModel):
4647 last_updated : dt .datetime
4748 latest : Totals
4849 province : str = ""
49- timelines : TimelinedLocation
50+ timelines : TimelinedLocation = None # FIXME
5051
5152
5253class AllLocations (pydantic .BaseModel ):
53- latest : Totals
54+ latest : Totals = None # FIXME
5455 locations : List [Country ]
5556
5657
@@ -124,8 +125,25 @@ def get_latest(request: fastapi.Request):
124125
125126
126127@APP .get ("/locations" , response_model = AllLocations )
127- def get_all_locations (country_code : str = None , timelines : int = 0 ):
128- return
128+ def get_all_locations (
129+ request : fastapi .Request , country_code : str = None , timelines : int = 0
130+ ):
131+ # Retrieve all the locations.
132+ locations = request .state .source .get_all ()
133+
134+ # Filtering my country code if provided.
135+ if country_code :
136+ locations = list (
137+ filter (
138+ lambda location : location .country_code == country_code .upper (),
139+ locations ,
140+ )
141+ )
142+ response_dict = {
143+ "locations" : [location .serialize (timelines ) for location in locations ]
144+ }
145+ LOGGER .info (f"response: { reprlib .repr (response_dict )} " )
146+ return response_dict
129147
130148
131149@APP .get ("/locations/{id}" , response_model = Location )
You can’t perform that action at this time.
0 commit comments