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

structural pattern applied #461

Closed atayyabi closed 3 years ago

atayyabi commented 3 years ago

There were functions that does data lookup for a key. Country code lookup and Population lookup are example of these. However it would be useful to have a centralized registry where you can perform all these lookup based on the key. Even though the type of data thats being looked up different, the manner of accessing the lookup the data would be the same. That is you'd provide a key and there would be a default value if the data is not present related to the key. The logic for Country code lookup and Population lookup yields different algorithms and the returned data is also different. Therefore I designed a lookup class that hides such details and exposes the functionality via a get method where u pass a key and if needed a default value. Then both the Country code lookup and Population lookup functions are converted in to sub classes of the lookup class where the get method implements the logic. An instance of these classes is registered in the lookup registry located at utils.lookup.py module. Now whenever we want to lookup data we just call the utils.lookup.get(, [,]) where lookup_type is in this PR is either "country_code" or "country_population".