diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 4ecdd0b6..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,36 +0,0 @@ -# Contribution to Coronavirus Tracker API - -First off, thanks for taking the time to contribute! -Every commit supports the open source ecosystem in case of [COVID-19](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic). - -## Testing - -We have a handful of unit tests to cover most of functions. -Please write new test cases for new code you create. - -## Submitting changes - -* If you're unable to find an open issue, [open a new one](https://github.com/ExpDev07/coronavirus-tracker-api/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible -* Open a new [GitHub Pull Request to coronavirus-tracker-api](https://github.com/ExpDev07/coronavirus-tracker-api/pulls) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Include the relevant issue number if applicable. -* We will love you forever if you include unit tests. We can always use more test coverage -* If you have updated [Pipefile](./Pipfile), you have to update `Pipfile.lock`, `requirements.txt` and `requirements-dev.txt`. See section [Update requirements files](./README.md#update-requirements-files). - -## Your First Code Contribution - -Unsure where to begin contributing to coronavirus-tracker-api ? You can start by looking through these issues labels: - -* [Enhancement issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/enhancement) - issues for new feature or request -* [Help wanted issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/help%20wanted) - extra attention is needed -* [Documentation issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/documentation) - improvements or additions to documentation - -## Styleguide - -Please follow [PEP8](https://www.python.org/dev/peps/pep-0008/) guide. -See [Running Test](./README.md#running-tests), [Linting](./README.md#linting) and [Formatting](./README.md#formatting) sections for further instructions to validate your change. - - -We encourage you to pitch in and join the [Coronavirus Tracker API Team](https://github.com/ExpDev07/coronavirus-tracker-api#contributors-)! - -Thanks! :heart: :heart: :heart: - -[Coronavirus Tracker API Team](https://github.com/ExpDev07/coronavirus-tracker-api#contributors-) diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..c23c76c8 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -10,12 +10,16 @@ "nyt": NYTLocationService(), } +class DataSourceRequest: + def __init__(self, request): # request is of Obj reference of Reqeust from FastAPI + self.request = request + + def get_data_source(self): + """ + Retrieves the provided data-source service. -def data_source(source): - """ - Retrieves the provided data-source service. - - :returns: The service. - :rtype: LocationService - """ - return DATA_SOURCES.get(source.lower()) + :returns: The service. + :rtype: LocationService + """ + request_source = self.request.query_params.get("source", default="jhu") # gets source parameters + return DATA_SOURCES.get(request_source.lower()) diff --git a/app/main.py b/app/main.py index b9aff949..c9ff29da 100644 --- a/app/main.py +++ b/app/main.py @@ -14,7 +14,7 @@ from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from .config import get_settings -from .data import data_source +from .data import DataSourceRequest from .routers import V1, V2 from .utils.httputils import setup_client_session, teardown_client_session @@ -74,17 +74,19 @@ async def add_datasource(request: Request, call_next): Attach the data source to the request.state. """ # Retrieve the datas ource from query param. - source = data_source(request.query_params.get("source", default="jhu")) + requested_data_source = DataSourceRequest(request) + data_source = requested_data_source.get_data_source() + - # Abort with 404 if source cannot be found. - if not source: + # Abort with 404 if data_source cannot be found. + if not data_source: return Response("The provided data-source was not found.", status_code=404) # Attach source to request. - request.state.source = source + request.state.data_source = data_source # Move on... - LOGGER.debug(f"source provided: {source.__class__.__name__}") + LOGGER.debug(f"source provided: {data_source.__class__.__name__}") response = await call_next(request) return response