Skip to content

Commit 396b7f9

Browse files
committed
add source enum
1 parent 1c7e4ae commit 396b7f9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

app/data/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from ..services.location.csbs import CSBSLocationService
33
from ..services.location.jhu import JhuLocationService
44
from ..services.location.nyt import NYTLocationService
5+
from ..utils.source_enum import SourceEnum
56

67
# Mapping of services to data-sources.
78
DATA_SOURCES = {
8-
"jhu": JhuLocationService(),
9-
"csbs": CSBSLocationService(),
10-
"nyt": NYTLocationService(),
9+
SourceEnum.JHU: JhuLocationService(),
10+
SourceEnum.CSBS: CSBSLocationService(),
11+
SourceEnum.NYT: NYTLocationService(),
1112
}
1213

1314

app/routers/v2.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ..data import DATA_SOURCES
77
from ..models import LatestResponse, LocationResponse, LocationsResponse
8-
8+
from ..utils.source_enum import SourceEnum
99
V2 = APIRouter()
1010

1111

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

17-
JHU = "jhu"
18-
CSBS = "csbs"
19-
NYT = "nyt"
20-
2117

2218
@V2.get("/latest", response_model=LatestResponse)
2319
async def get_latest(
24-
request: Request, source: Sources = Sources.JHU
20+
request: Request, source: Sources = SourceEnum.JHU
2521
): # pylint: disable=unused-argument
2622
"""
2723
Getting latest amount of total confirmed cases, deaths, and recoveries.
@@ -93,7 +89,7 @@ async def get_locations(
9389
# pylint: disable=invalid-name
9490
@V2.get("/locations/{id}", response_model=LocationResponse)
9591
async def get_location_by_id(
96-
request: Request, id: int, source: Sources = Sources.JHU, timelines: bool = True
92+
request: Request, id: int, source: Sources = SourceEnum.JHU, timelines: bool = True
9793
):
9894
"""
9995
Getting specific location by id.

app/utils/source_enum.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class SourceEnum(Enum):
2+
JHU = "jhu"
3+
CSBS = "csbs"
4+
NYT = "nyt"

0 commit comments

Comments
 (0)