fix(api): lowercase default metric names to match ALLOWED_METRICS
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -136,7 +136,7 @@ async def list_commodities():
|
||||
@api_key_required(scopes=["read"])
|
||||
async def commodity_metrics(code: int):
|
||||
"""Time series metrics for a commodity. Query params: metrics, start_year, end_year."""
|
||||
raw_metrics = request.args.getlist("metrics") or ["Production", "Exports", "Imports", "Ending_Stocks"]
|
||||
raw_metrics = request.args.getlist("metrics") or ["production", "exports", "imports", "ending_stocks"]
|
||||
metrics = [m for m in raw_metrics if m in analytics.ALLOWED_METRICS]
|
||||
if not metrics:
|
||||
return jsonify({"error": f"No valid metrics. Allowed: {sorted(analytics.ALLOWED_METRICS)}"}), 400
|
||||
@@ -152,7 +152,7 @@ async def commodity_metrics(code: int):
|
||||
@api_key_required(scopes=["read"])
|
||||
async def commodity_countries(code: int):
|
||||
"""Country ranking for a commodity. Query params: metric, limit."""
|
||||
metric = request.args.get("metric", "Production")
|
||||
metric = request.args.get("metric", "production")
|
||||
if metric not in analytics.ALLOWED_METRICS:
|
||||
return jsonify({"error": f"Invalid metric. Allowed: {sorted(analytics.ALLOWED_METRICS)}"}), 400
|
||||
|
||||
@@ -368,7 +368,7 @@ async def commodity_metrics_csv(code: int):
|
||||
return jsonify({"error": "CSV export requires a Starter or Pro plan"}), 403
|
||||
|
||||
raw_metrics = request.args.getlist("metrics") or [
|
||||
"Production", "Exports", "Imports", "Ending_Stocks", "Total_Distribution",
|
||||
"production", "exports", "imports", "ending_stocks", "total_distribution",
|
||||
]
|
||||
metrics = [m for m in raw_metrics if m in analytics.ALLOWED_METRICS]
|
||||
if not metrics:
|
||||
|
||||
Reference in New Issue
Block a user