diff --git a/app/main.py b/app/main.py index 5b62ac9c..8e0b367c 100644 --- a/app/main.py +++ b/app/main.py @@ -89,7 +89,7 @@ def get_latest(request: fastapi.Request, source: Sources = "jhu"): @V2.get( - "/locations", response_model=models.AllLocations, response_model_exclude_unset=True + "/locations", response_model=models.Locations, response_model_exclude_unset=True ) def get_all_locations( request: fastapi.Request, @@ -131,8 +131,9 @@ async def sources(): """ return {"sources": list(data_sources.keys())} - +# Include routers. APP.include_router(V2, prefix="/v2-beta", tags=["v2"]) + # mount the existing Flask app # v1 @ / # v2 @ /v2 diff --git a/app/models.py b/app/models.py index a67b7573..36b1396f 100644 --- a/app/models.py +++ b/app/models.py @@ -3,48 +3,45 @@ ~~~~~~~~~~~~~ Reponse data models. """ -import datetime as dt +from pydantic import BaseModel from typing import Dict, List -import pydantic - - -class Totals(pydantic.BaseModel): +class Totals(BaseModel): confirmed: int deaths: int recovered: int -class Latest(pydantic.BaseModel): +class Latest(BaseModel): latest: Totals -class TimelineStats(pydantic.BaseModel): +class TimelineStats(BaseModel): latest: int - timeline: Dict[str, int] + timeline: Dict[str, int] = {} -class TimelinedLocation(pydantic.BaseModel): +class TimelinedLocation(BaseModel): confirmed: TimelineStats deaths: TimelineStats recovered: TimelineStats -class Country(pydantic.BaseModel): - coordinates: Dict +class Country(BaseModel): + id: int country: str country_code: str - id: int - last_updated: dt.datetime - latest: Totals province: str = "" - timelines: TimelinedLocation = None # FIXME + last_updated: str # TODO use datetime.datetime type. + coordinates: Dict + latest: Totals + timelines: TimelinedLocation = {} -class AllLocations(pydantic.BaseModel): +class Locations(BaseModel): latest: Totals - locations: List[Country] + locations: List[Country] = [] -class Location(pydantic.BaseModel): +class Location(BaseModel): location: Country diff --git a/coronavirus-tracker-api-swagger.yaml b/coronavirus-tracker-api-swagger.yaml deleted file mode 100644 index d17b9d42..00000000 --- a/coronavirus-tracker-api-swagger.yaml +++ /dev/null @@ -1,152 +0,0 @@ -swagger: '2.0' -info: - description: 'Corona Virus Tracker API based on JHU data sets. https://github.com/ExpDev07/coronavirus-tracker-api' - version: 1.0.0 - title: Corona Virus Tracker API - contact: - url: https://github.com/ExpDev07/coronavirus-tracker-api -host: coronavirus-tracker-api.herokuapp.com -basePath: /v2 -schemes: - - https -paths: - /latest: - get: - summary: Latest global Corona stats - operationId: latest - produces: - - application/json - responses: - '200': - description: successful operation - schema: - type: object - properties: - latest: - type: object - properties: - confirmed: - type: number - example: 214910 - deaths: - type: number - example: 8733 - recovered: - type: number - example: 83207 - /locations: - get: - summary: All Locations - operationId: allLocations - produces: - - application/json - parameters: - - name: country_code - in: query - description: "ISO alpha 2 country code. https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2" - required: false - type: string - x-example: US - - name: timelines - in: query - description: "Include timeline objects in response? true or false" - required: false - type: string - x-example: true - responses: - '200': - description: successful operation - schema: - type: object - properties: - locations: - type: array - items: - $ref: '#/definitions/Location' - '/locations/{id}': - get: - summary: location - operationId: location - produces: - - application/json - parameters: - - name: id - in: path - description: "Internal ID" - required: true - type: string - x-example: 39 - responses: - '200': - description: successful operation - schema: - type: object - properties: - location: - $ref: '#/definitions/Location' - '404': - description: Location not found -definitions: - Location: - type: object - properties: - coordinates: - type: object - properties: - latitude: - type: string - example: "47.4009" - longitude: - type: string - example: "-121.4905" - country: - type: string - example: "US" - country_code: - type: string - example: US - id: - type: number - example: 98 - latest: - type: object - properties: - confirmed: - type: number - example: 1014 - deaths: - type: number - example: 55 - recovered: - type: number - example: 10 - province: - type: string - example: "Washington" - timelines: - type: object - properties: - confirmed: - type: object - properties: - latest: - type: number - example: 1014 - timeline: - type: object - deaths: - type: object - properties: - latest: - type: number - example: 55 - timeline: - type: object - recovered: - type: object - properties: - latest: - type: number - example: 10 - timeline: - type: object