1212import uvicorn
1313from fastapi .middleware .wsgi import WSGIMiddleware
1414
15- from .data import data_source
15+ from . import models
1616from .core import create_app
17-
18- # #################################
19- # Models
20- # #################################
21-
22-
23- class Totals (pydantic .BaseModel ):
24- confirmed : int
25- deaths : int
26- recovered : int
27-
28-
29- class Latest (pydantic .BaseModel ):
30- latest : Totals
31-
32-
33- class TimelineStats (pydantic .BaseModel ):
34- latest : int
35- timeline : Dict [str , int ]
36-
37-
38- class TimelinedLocation (pydantic .BaseModel ):
39- confirmed : TimelineStats
40- deaths : TimelineStats
41- recovered : TimelineStats
42-
43-
44- class Country (pydantic .BaseModel ):
45- coordinates : Dict
46- country : str
47- country_code : str
48- id : int
49- last_updated : dt .datetime
50- latest : Totals
51- province : str = ""
52- timelines : TimelinedLocation = None # FIXME
53-
54-
55- class AllLocations (pydantic .BaseModel ):
56- latest : Totals
57- locations : List [Country ]
58-
59-
60- class Location (pydantic .BaseModel ):
61- location : Country
62-
17+ from .data import data_source
6318
6419# ################
6520# Dependencies
@@ -113,7 +68,7 @@ async def handle_validation_error(
11368# ################
11469
11570
116- @APP .get ("/latest" , response_model = Latest )
71+ @APP .get ("/latest" , response_model = models . Latest )
11772def get_latest (request : fastapi .Request ):
11873 """Getting latest amount of total confirmed cases, deaths, and recoveries."""
11974 locations = request .state .source .get_all ()
@@ -126,7 +81,7 @@ def get_latest(request: fastapi.Request):
12681 }
12782
12883
129- @APP .get ("/locations" , response_model = AllLocations )
84+ @APP .get ("/locations" , response_model = models . AllLocations )
13085def get_all_locations (
13186 request : fastapi .Request , country_code : str = None , timelines : int = 0
13287):
@@ -152,10 +107,11 @@ def get_all_locations(
152107 }
153108
154109
155- @APP .get ("/locations/{id}" , response_model = Location )
110+ @APP .get ("/locations/{id}" , response_model = models . Location )
156111def get_location_by_id (request : fastapi .Request , id : int , timelines : int = 1 ):
157112 return {"location" : request .state .source .get (id ).serialize (timelines )}
158113
114+
159115# mount the existing Flask app to /v2
160116APP .mount ("/v2" , WSGIMiddleware (create_app ()))
161117
0 commit comments