Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add source enum
  • Loading branch information
lilywuyanru committed Jul 24, 2021
commit 396b7f92501e154eca36a92ecbfa9d5becb67179
7 changes: 4 additions & 3 deletions app/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService
from ..utils.source_enum import SourceEnum

# Mapping of services to data-sources.
DATA_SOURCES = {
"jhu": JhuLocationService(),
"csbs": CSBSLocationService(),
"nyt": NYTLocationService(),
SourceEnum.JHU: JhuLocationService(),
SourceEnum.CSBS: CSBSLocationService(),
SourceEnum.NYT: NYTLocationService(),
}


Expand Down
10 changes: 3 additions & 7 deletions app/routers/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..data import DATA_SOURCES
from ..models import LatestResponse, LocationResponse, LocationsResponse

from ..utils.source_enum import SourceEnum
V2 = APIRouter()


Expand All @@ -14,14 +14,10 @@ class Sources(str, enum.Enum):
A source available for retrieving data.
"""

JHU = "jhu"
CSBS = "csbs"
NYT = "nyt"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have an enum defined.

I agree with the essential direction of the PR though. To actually use the enum.

Maybe we ought to define it in app/data.


@V2.get("/latest", response_model=LatestResponse)
async def get_latest(
request: Request, source: Sources = Sources.JHU
request: Request, source: Sources = SourceEnum.JHU
): # pylint: disable=unused-argument
"""
Getting latest amount of total confirmed cases, deaths, and recoveries.
Expand Down Expand Up @@ -93,7 +89,7 @@ async def get_locations(
# pylint: disable=invalid-name
@V2.get("/locations/{id}", response_model=LocationResponse)
async def get_location_by_id(
request: Request, id: int, source: Sources = Sources.JHU, timelines: bool = True
request: Request, id: int, source: Sources = SourceEnum.JHU, timelines: bool = True
):
"""
Getting specific location by id.
Expand Down
4 changes: 4 additions & 0 deletions app/utils/source_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SourceEnum(Enum):
JHU = "jhu"
CSBS = "csbs"
NYT = "nyt"