-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2039 from PolicyEngine/1992_metadata_endpoint_to_…
…blueprint Refactor metadata to blueprint/service
- Loading branch information
Showing
8 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- bump: patch | ||
changes: | ||
changed: | ||
- /<country_id>/metadata is now implemented via a blueprint/service instead of endpoint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from flask import Blueprint | ||
|
||
from policyengine_api.utils.payload_validators import validate_country | ||
from policyengine_api.services.metadata_service import MetadataService | ||
|
||
metadata_bp = Blueprint("metadata", __name__) | ||
metadata_service = MetadataService() | ||
|
||
|
||
@metadata_bp.route("/<country_id>/metadata", methods=["GET"]) | ||
@validate_country | ||
def get_metadata(country_id: str) -> dict: | ||
"""Get metadata for a country. | ||
Args: | ||
country_id (str): The country ID. | ||
""" | ||
return metadata_service.get_metadata(country_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from policyengine_api.country import COUNTRIES | ||
|
||
|
||
class MetadataService: | ||
def get_metadata(self, country_id: str) -> dict: | ||
country = COUNTRIES.get(country_id) | ||
if country == None: | ||
raise RuntimeError( | ||
f"Attempted to get metadata for a nonexistant country: '{country_id}'" | ||
) | ||
|
||
return country.metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters