Skip to content

Commit

Permalink
feat: Basic Werkzeug route validators
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Dec 12, 2024
1 parent c0fdde9 commit f789559
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion policyengine_api/routes/economy_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@validate_country
@economy_bp.route(
"/<country_id>/economy/<policy_id>/over/<baseline_policy_id>",
"/<country_id>/economy/<int:policy_id>/over/<int:baseline_policy_id>",
methods=["GET"],
)
def get_economic_impact(country_id, policy_id, baseline_policy_id):
Expand Down
21 changes: 6 additions & 15 deletions policyengine_api/routes/household_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@
household_service = HouseholdService()


@household_bp.route("/<country_id>/household/<household_id>", methods=["GET"])
@household_bp.route("/<country_id>/household/<int:household_id>", methods=["GET"])
@validate_country
def get_household(country_id: str, household_id: str) -> Response:
def get_household(country_id: str, household_id: int) -> Response:
"""
Get a household's input data with a given ID.
Args:
country_id (str): The country ID.
household_id (str): The household ID.
household_id (int): The household ID.
"""
print(f"Got request for household {household_id} in country {country_id}")

# Ensure that household ID is a number
try:
household_id = int(household_id)
except ValueError:
return Response(
status=400,
response=f"Invalid household ID; household ID must be a number",
)

try:
household: dict | None = household_service.get_household(
country_id, household_id
Expand Down Expand Up @@ -128,15 +119,15 @@ def post_household(country_id: str) -> Response:
)


@household_bp.route("/<country_id>/household/<household_id>", methods=["PUT"])
@household_bp.route("/<country_id>/household/<int:household_id>", methods=["PUT"])
@validate_country
def update_household(country_id: str, household_id: str) -> Response:
def update_household(country_id: str, household_id: int) -> Response:
"""
Update a household's input data.
Args:
country_id (str): The country ID.
household_id (str): The household ID.
household_id (int): The household ID.
"""

# Validate payload
Expand Down

0 comments on commit f789559

Please sign in to comment.