Skip to content

Commit f789559

Browse files
committed
feat: Basic Werkzeug route validators
1 parent c0fdde9 commit f789559

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

policyengine_api/routes/economy_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@validate_country
1414
@economy_bp.route(
15-
"/<country_id>/economy/<policy_id>/over/<baseline_policy_id>",
15+
"/<country_id>/economy/<int:policy_id>/over/<int:baseline_policy_id>",
1616
methods=["GET"],
1717
)
1818
def get_economic_impact(country_id, policy_id, baseline_policy_id):

policyengine_api/routes/household_routes.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,18 @@
1414
household_service = HouseholdService()
1515

1616

17-
@household_bp.route("/<country_id>/household/<household_id>", methods=["GET"])
17+
@household_bp.route("/<country_id>/household/<int:household_id>", methods=["GET"])
1818
@validate_country
19-
def get_household(country_id: str, household_id: str) -> Response:
19+
def get_household(country_id: str, household_id: int) -> Response:
2020
"""
2121
Get a household's input data with a given ID.
2222
2323
Args:
2424
country_id (str): The country ID.
25-
household_id (str): The household ID.
25+
household_id (int): The household ID.
2626
"""
2727
print(f"Got request for household {household_id} in country {country_id}")
2828

29-
# Ensure that household ID is a number
30-
try:
31-
household_id = int(household_id)
32-
except ValueError:
33-
return Response(
34-
status=400,
35-
response=f"Invalid household ID; household ID must be a number",
36-
)
37-
3829
try:
3930
household: dict | None = household_service.get_household(
4031
country_id, household_id
@@ -128,15 +119,15 @@ def post_household(country_id: str) -> Response:
128119
)
129120

130121

131-
@household_bp.route("/<country_id>/household/<household_id>", methods=["PUT"])
122+
@household_bp.route("/<country_id>/household/<int:household_id>", methods=["PUT"])
132123
@validate_country
133-
def update_household(country_id: str, household_id: str) -> Response:
124+
def update_household(country_id: str, household_id: int) -> Response:
134125
"""
135126
Update a household's input data.
136127
137128
Args:
138129
country_id (str): The country ID.
139-
household_id (str): The household ID.
130+
household_id (int): The household ID.
140131
"""
141132

142133
# Validate payload

0 commit comments

Comments
 (0)