feat: 添加目标体重设置功能

- UserConfig 模型添加 target_weight 字段
- 新增 POST /api/config 端点用于更新用户配置
- 设置页面添加目标体重输入框及目标 BMI 自动计算
- BMI 分析使用用户设置的目标体重计算达成预估
- 修复测试 fixture 的 save_config 参数问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 17:39:24 +08:00
parent 50c33451ef
commit 842998893a
4 changed files with 178 additions and 19 deletions

View File

@@ -49,7 +49,7 @@ def populated_db():
age=28, gender="male", height=175.0, weight=72.0,
activity_level="moderate", goal="maintain",
)
db.save_config(config)
db.save_config(1, config)
# 今日数据
db.add_exercise(Exercise(
@@ -111,6 +111,19 @@ class TestConfigEndpoint:
data = response.json()
assert data["activity_level"] == "moderate"
def test_update_config_target_weight(self, client, populated_db):
"""测试更新目标体重"""
response = client.post("/api/config", json={"target_weight": 65.0})
assert response.status_code == 200
data = response.json()
assert data["target_weight"] == 65.0
# 验证可以获取到保存的值
get_response = client.get("/api/config")
get_data = get_response.json()
assert get_data["target_weight"] == 65.0
class TestTodayEndpoint:
"""今日概览接口测试"""