ExpDev07 / coronavirus-tracker-api

🦠 A simple and fast (< 200ms) API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak. It's written in python using the 🔥 FastAPI framework. Supports multiple sources!
https://coronavirus-tracker-api.herokuapp.com
GNU General Public License v3.0
1.59k stars 323 forks source link

adapter pattern is created #433

Closed bjy19 closed 3 years ago

bjy19 commented 3 years ago

Why I used it. In this API there are three different classes called csbc.py, jhu.py, and nyt.py from where we get all data. Here we need to call 3 different types of methods for getting same data. That's why I created an adapter that provides data from the appropriate source with one single method.

How I made it. In the services/location/__init__.py file I made an adapter class called LocationService. This class provides two common methods for any type of source. The name of these methods are get_all() and get(). I am storing the object of adapter classes inside the request.state.source. Hence when we call it from router v2.py then we only need to watch the methods of the adapter.