Skip to content

Commit 1cfdc2c

Browse files
committed
WIP get_all_locations
1 parent 20c49c2 commit 1cfdc2c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

app/main.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime as dt
55
import logging
66
import os
7+
import reprlib
78
from typing import Dict, List
89

910
import 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

5253
class 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)

0 commit comments

Comments
 (0)