Skip to content

Commit 304de58

Browse files
author
ExpDev07
committed
changed start dev script to "pipenv run dev" and "pipenv run start" + renamed models + some cleanup
1 parent 45dc4d4 commit 304de58

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ uvicorn = "*"
2323
python_version = "3.8"
2424

2525
[scripts]
26-
dev_app = "uvicorn app.main:APP --reload"
27-
app = "uvicorn app.main:APP"
26+
dev = "uvicorn app.main:APP --reload"
27+
start = "uvicorn app.main:APP"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ You will need the following things properly installed on your computer.
393393

394394
## Running / Development
395395

396-
* `flask run`
396+
* `pipenv run dev`
397397
* Visit your app at [http://localhost:5000](http://localhost:5000).
398398

399399
### Running Tests

app/main.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def add_datasource(request: fastapi.Request, call_next):
6565
request.state.source = source
6666

6767
# Move on...
68-
LOGGER.info(f'source: {source.__class__.__name__}')
68+
LOGGER.info(f'source provided: {source.__class__.__name__}')
6969
response = await call_next(request)
7070
return response
7171

@@ -92,7 +92,7 @@ async def handle_validation_error(
9292
V2 = fastapi.APIRouter()
9393

9494

95-
@V2.get('/latest', response_model=models.Latest)
95+
@V2.get('/latest', response_model=models.LatestResponse)
9696
def get_latest(request: fastapi.Request, source: Sources = 'jhu'):
9797
"""
9898
Getting latest amount of total confirmed cases, deaths, and recoveries.
@@ -101,20 +101,20 @@ def get_latest(request: fastapi.Request, source: Sources = 'jhu'):
101101
return {
102102
'latest': {
103103
'confirmed': sum(map(lambda location: location.confirmed, locations)),
104-
'deaths': sum(map(lambda location: location.deaths, locations)),
104+
'deaths' : sum(map(lambda location: location.deaths, locations)),
105105
'recovered': sum(map(lambda location: location.recovered, locations)),
106106
}
107107
}
108108

109109

110110
@V2.get(
111-
'/locations', response_model=models.Locations, response_model_exclude_unset=True
111+
'/locations', response_model=models.LocationsResponse, response_model_exclude_unset=True
112112
)
113113
def get_locations(
114114
request: fastapi.Request,
115+
source: Sources = 'jhu',
115116
country_code: str = None,
116117
timelines: bool = False,
117-
source: Sources = 'jhu',
118118
):
119119
"""
120120
Getting the locations.
@@ -126,23 +126,23 @@ def get_locations(
126126
if country_code:
127127
locations = list(
128128
filter(
129-
lambda location: location.country_code == country_code.upper(),
130-
locations,
129+
lambda location: location.country_code == country_code.upper(), locations,
131130
)
132131
)
133-
# FIXME: timelines are not showing up
132+
133+
# Return final serialized data.
134134
return {
135135
'latest': {
136136
'confirmed': sum(map(lambda location: location.confirmed, locations)),
137-
'deaths': sum(map(lambda location: location.deaths, locations)),
137+
'deaths' : sum(map(lambda location: location.deaths, locations)),
138138
'recovered': sum(map(lambda location: location.recovered, locations)),
139139
},
140140
'locations': [location.serialize(timelines) for location in locations],
141141
}
142142

143143

144-
@V2.get('/locations/{id}', response_model=models.Location)
145-
def get_location_by_id(request: fastapi.Request, id: int, timelines: bool = True):
144+
@V2.get('/locations/{id}', response_model=models.LocationResponse)
145+
def get_location_by_id(request: fastapi.Request, id: int, source: Sources = 'jhu', timelines: bool = True):
146146
"""
147147
Getting specific location by id.
148148
"""

app/models.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,39 @@
66
from pydantic import BaseModel
77
from typing import Dict, List
88

9-
class Totals(BaseModel):
9+
class Latest(BaseModel):
1010
confirmed: int
1111
deaths: int
1212
recovered: int
1313

14+
class LatestResponse(BaseModel):
15+
latest: Latest
1416

15-
class Latest(BaseModel):
16-
latest: Totals
17-
18-
19-
class TimelineStats(BaseModel):
17+
class Timeline(BaseModel):
2018
latest: int
2119
timeline: Dict[str, int] = {}
2220

21+
class Timelines(BaseModel):
22+
confirmed: Timeline
23+
deaths: Timeline
24+
recovered: Timeline
2325

24-
class TimelinedLocation(BaseModel):
25-
confirmed: TimelineStats
26-
deaths: TimelineStats
27-
recovered: TimelineStats
28-
29-
30-
class Country(BaseModel):
26+
class Location(BaseModel):
3127
id: int
3228
country: str
3329
country_code: str
34-
county: str = None
30+
county: str = ''
3531
province: str = ''
3632
last_updated: str # TODO use datetime.datetime type.
3733
coordinates: Dict
38-
latest: Totals
39-
timelines: TimelinedLocation = {}
34+
latest: Latest
35+
timelines: Timelines = {}
4036

4137

42-
class Locations(BaseModel):
43-
latest: Totals
44-
locations: List[Country] = []
38+
class LocationsResponse(BaseModel):
39+
latest: Latest
40+
locations: List[Location] = []
4541

4642

47-
class Location(BaseModel):
48-
location: Country
43+
class LocationResponse(BaseModel):
44+
location: Location

0 commit comments

Comments
 (0)