Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor metadata to blueprint/service #2039

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
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.
5 changes: 3 additions & 2 deletions policyengine_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
simulation_analysis_bp,
)
from policyengine_api.routes.tracer_analysis_routes import tracer_analysis_bp
from policyengine_api.routes.metadata_routes import metadata_bp

from .endpoints import (
get_home,
get_metadata,
get_household,
post_household,
update_household,
Expand Down Expand Up @@ -57,7 +58,7 @@

app.route("/", methods=["GET"])(get_home)

app.route("/<country_id>/metadata", methods=["GET"])(get_metadata)
app.register_blueprint(metadata_bp)
anth-volk marked this conversation as resolved.
Show resolved Hide resolved

app.route("/<country_id>/household/<household_id>", methods=["GET"])(
get_household
Expand Down
1 change: 0 additions & 1 deletion policyengine_api/endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .home import get_home
from .metadata import get_metadata
from .household import (
get_household,
post_household,
Expand Down
12 changes: 0 additions & 12 deletions policyengine_api/endpoints/metadata.py

This file was deleted.

18 changes: 18 additions & 0 deletions policyengine_api/routes/metadata_routes.py
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"])
anth-volk marked this conversation as resolved.
Show resolved Hide resolved
@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)
12 changes: 12 additions & 0 deletions policyengine_api/services/metadata_service.py
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
2 changes: 1 addition & 1 deletion tests/python/test_units.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from policyengine_api.endpoints.metadata import get_metadata
from policyengine_api.routes.metadata_routes import get_metadata


def test_units():
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_yearly_var_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

from policyengine_api.endpoints.household import get_household_under_policy
from policyengine_api.endpoints.metadata import get_metadata
from policyengine_api.routes.metadata_routes import get_metadata
from policyengine_api.endpoints.policy import get_policy
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS
from policyengine_api.data import database
Expand Down
Loading