"""Profile, units and sync preferences.""" from flask import Blueprint, request, g, jsonify from auth import require_auth from services import settings as settings_svc from services.insights import BAND_SOURCES from services import fitness_age bp = Blueprint("settings", __name__) @bp.route("", methods=["GET"]) @bp.route("/", methods=["GET"]) @require_auth def get_settings(): return jsonify(settings_svc.get_settings(g.user_id)) @bp.route("", methods=["PUT"]) @bp.route("/", methods=["PUT"]) @require_auth def put_settings(): try: return jsonify(settings_svc.save_settings(g.user_id, request.json or {})) except settings_svc.InvalidSetting as e: return jsonify({"error": str(e)}), 400 @bp.route("/options", methods=["GET"]) @require_auth def options(): """The values the pickers may offer, so the UI never invents one the backend would reject.""" return jsonify({ "sexes": list(settings_svc.SEXES), "units": list(settings_svc.UNITS), "autoSyncMinutes": list(settings_svc.INTERVALS), "historyDays": list(settings_svc.HISTORY), }) @bp.route("/rating-basis", methods=["GET"]) @require_auth def rating_basis(): """Where every rating in the app comes from. Surfaced in 设置 because a band that colours a number 偏低 is making a claim, and the user is entitled to see what that claim rests on. """ return jsonify({ "fitnessAge": fitness_age.BASIS, "bands": BAND_SOURCES, "note": ( "参考区间用于给数字一个位置感,不是诊断标准。" "AI 只负责解读这些结果,不参与设定任何阈值。" ), })