Skip to content

Commit f7b7354

Browse files
author
ExpDev07
committed
fixed wrong date format and timelines appearing null
1 parent 49800c3 commit f7b7354

File tree

3 files changed

+18
-172
lines changed

3 files changed

+18
-172
lines changed

app/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_latest(request: fastapi.Request, source: Sources = "jhu"):
8989

9090

9191
@V2.get(
92-
"/locations", response_model=models.AllLocations, response_model_exclude_unset=True
92+
"/locations", response_model=models.Locations, response_model_exclude_unset=True
9393
)
9494
def get_all_locations(
9595
request: fastapi.Request,
@@ -131,8 +131,9 @@ async def sources():
131131
"""
132132
return {"sources": list(data_sources.keys())}
133133

134-
134+
# Include routers.
135135
APP.include_router(V2, prefix="/v2-beta", tags=["v2"])
136+
136137
# mount the existing Flask app
137138
# v1 @ /
138139
# v2 @ /v2

app/models.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,45 @@
33
~~~~~~~~~~~~~
44
Reponse data models.
55
"""
6-
import datetime as dt
6+
from pydantic import BaseModel
77
from typing import Dict, List
88

9-
import pydantic
10-
11-
12-
class Totals(pydantic.BaseModel):
9+
class Totals(BaseModel):
1310
confirmed: int
1411
deaths: int
1512
recovered: int
1613

1714

18-
class Latest(pydantic.BaseModel):
15+
class Latest(BaseModel):
1916
latest: Totals
2017

2118

22-
class TimelineStats(pydantic.BaseModel):
19+
class TimelineStats(BaseModel):
2320
latest: int
24-
timeline: Dict[str, int]
21+
timeline: Dict[str, int] = {}
2522

2623

27-
class TimelinedLocation(pydantic.BaseModel):
24+
class TimelinedLocation(BaseModel):
2825
confirmed: TimelineStats
2926
deaths: TimelineStats
3027
recovered: TimelineStats
3128

3229

33-
class Country(pydantic.BaseModel):
34-
coordinates: Dict
30+
class Country(BaseModel):
31+
id: int
3532
country: str
3633
country_code: str
37-
id: int
38-
last_updated: dt.datetime
39-
latest: Totals
4034
province: str = ""
41-
timelines: TimelinedLocation = None # FIXME
35+
last_updated: str # TODO use datetime.datetime type.
36+
coordinates: Dict
37+
latest: Totals
38+
timelines: TimelinedLocation = {}
4239

4340

44-
class AllLocations(pydantic.BaseModel):
41+
class Locations(BaseModel):
4542
latest: Totals
46-
locations: List[Country]
43+
locations: List[Country] = []
4744

4845

49-
class Location(pydantic.BaseModel):
46+
class Location(BaseModel):
5047
location: Country

coronavirus-tracker-api-swagger.yaml

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)