优化训练计划项目管理功能

- 更新训练项目文档,增加与动作库的智能关联和简化接口操作的说明
- 移除批量操作接口,专注于单项操作,提升用户体验
- 增强数据模型,确保训练项目与动作库的关联性,提升数据一致性和查询性能
- 更新服务逻辑,支持动作存在性验证,确保数据的准确性和完整性
This commit is contained in:
richarjiang
2025-08-15 11:37:11 +08:00
parent 8edc27b0ad
commit bea71af5d3
8 changed files with 565 additions and 448 deletions

View File

@@ -1,4 +1,6 @@
# 训练计划项目管理 API 使用示例
# 训练计划项目管理 API 使用示例(优化版)
这个版本展示了优化后的 API 设计,重点是与动作库的智能关联和简化的接口操作。
## 创建一个完整的训练计划项目
@@ -35,139 +37,169 @@ Content-Type: application/json
}
```
### 2. 批量添加训练项目
### 2. 逐个添加训练项目(关联动作库)
#### 添加热身项目
```bash
POST /training-plans/plan_1705123456789_abc123/exercises/batch
POST /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
Content-Type: application/json
{
"exercises": [
{
"key": "warmup_dynamic",
"name": "动态热身",
"category": "热身",
"durationSec": 300,
"itemType": "exercise",
"note": "轻松活动关节,准备训练"
},
{
"key": "note_safety",
"name": "安全提醒",
"note": "如感到不适请立即停止,保持正确呼吸",
"itemType": "note"
},
{
"key": "squat_exercise",
"name": "深蹲训练",
"category": "下肢力量",
"sets": 3,
"reps": 15,
"restSec": 60,
"itemType": "exercise",
"note": "下蹲时膝盖不超过脚尖"
},
{
"key": "rest_squat",
"name": "组间休息",
"durationSec": 90,
"itemType": "rest"
},
{
"key": "pushup_exercise",
"name": "俯卧撑",
"category": "上肢力量",
"sets": 3,
"reps": 12,
"restSec": 60,
"itemType": "exercise",
"note": "保持身体一条直线"
},
{
"key": "rest_pushup",
"name": "组间休息",
"durationSec": 90,
"itemType": "rest"
},
{
"key": "plank_exercise",
"name": "平板支撑",
"category": "核心力量",
"sets": 3,
"durationSec": 60,
"restSec": 45,
"itemType": "exercise",
"note": "腹部收紧,不要塌腰"
},
{
"key": "cooldown_stretch",
"name": "拉伸放松",
"category": "拉伸",
"durationSec": 600,
"itemType": "exercise",
"note": "充分拉伸训练过的肌群"
}
]
"exerciseKey": "dynamic_warmup", // 关联动作库中的动态热身
"name": "动态热身",
"durationSec": 300,
"itemType": "exercise",
"note": "轻松活动关节,准备训练"
}
```
响应:
```json
[
{
"id": "ex_1705123456790_def456",
"trainingPlanId": "plan_1705123456789_abc123",
"key": "warmup_dynamic",
"name": "动态热身",
"category": "热身",
"sets": 0,
"durationSec": 300,
"note": "轻松活动关节,准备训练",
"itemType": "exercise",
"completed": false,
"sortOrder": 1,
"createdAt": "2024-01-10T10:35:00.000Z",
"updatedAt": "2024-01-10T10:35:00.000Z"
},
// ... 其他项目
]
#### 添加安全提醒
```bash
POST /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
Content-Type: application/json
{
"name": "安全提醒",
"note": "如感到不适请立即停止,保持正确呼吸",
"itemType": "note"
}
```
### 3. 获取训练项目列表
#### 添加深蹲训练
```bash
POST /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
Content-Type: application/json
{
"exerciseKey": "squat", // 关联动作库中的深蹲
"name": "深蹲训练",
"sets": 3,
"reps": 15,
"restSec": 60,
"itemType": "exercise",
"note": "下蹲时膝盖不超过脚尖"
}
```
#### 添加休息时间
```bash
POST /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
Content-Type: application/json
{
"name": "组间休息",
"durationSec": 90,
"itemType": "rest"
}
```
#### 添加俯卧撑训练
```bash
POST /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
Content-Type: application/json
{
"exerciseKey": "pushup", // 关联动作库中的俯卧撑
"name": "俯卧撑训练",
"sets": 3,
"reps": 12,
"restSec": 60,
"itemType": "exercise",
"note": "保持身体一条直线"
}
```
```
每个添加请求的响应示例:
```json
{
"id": "ex_1705123456790_def456",
"trainingPlanId": "plan_1705123456789_abc123",
"exerciseKey": "squat",
"name": "深蹲训练",
"sets": 3,
"reps": 15,
"restSec": 60,
"note": "下蹲时膝盖不超过脚尖",
"itemType": "exercise",
"completed": false,
"sortOrder": 3,
"createdAt": "2024-01-10T10:35:00.000Z",
"updatedAt": "2024-01-10T10:35:00.000Z"
}
```
### 3. 获取训练项目列表(包含动作库信息)
```bash
GET /training-plans/plan_1705123456789_abc123/exercises
Authorization: Bearer {token}
```
响应按sortOrder排序的完整项目列表
响应按sortOrder排序的完整项目列表,包含关联的动作信息
```json
[
{
"id": "ex_1705123456790_def456",
"trainingPlanId": "plan_1705123456789_abc123",
"key": "warmup_dynamic",
"exerciseKey": "dynamic_warmup",
"name": "动态热身",
"category": "热身",
"sets": 0,
"durationSec": 300,
"note": "轻松活动关节,准备训练",
"itemType": "exercise",
"completed": false,
"sortOrder": 1
"sortOrder": 1,
"exercise": {
"key": "dynamic_warmup",
"name": "动态热身",
"description": "通过各种动态动作激活身体,为训练做准备",
"categoryKey": "warmup",
"categoryName": "热身"
}
},
{
"id": "ex_1705123456791_ghi789",
"trainingPlanId": "plan_1705123456789_abc123",
"key": "note_safety",
"name": "安全提醒",
"note": "如感到不适请立即停止,保持正确呼吸",
"itemType": "note",
"completed": false,
"sortOrder": 2
},
{
"id": "ex_1705123456792_jkl012",
"trainingPlanId": "plan_1705123456789_abc123",
"exerciseKey": "squat",
"name": "深蹲训练",
"sets": 3,
"reps": 15,
"restSec": 60,
"note": "下蹲时膝盖不超过脚尖",
"itemType": "exercise",
"completed": false,
"sortOrder": 3,
"exercise": {
"key": "squat",
"name": "深蹲",
"description": "下肢力量训练的基础动作,主要锻炼大腿和臀部肌肉",
"categoryKey": "strength",
"categoryName": "力量训练"
}
},
{
"id": "ex_1705123456793_mno345",
"trainingPlanId": "plan_1705123456789_abc123",
"name": "组间休息",
"durationSec": 90,
"itemType": "rest",
"completed": false,
"sortOrder": 4
}
// ... 更多项目
]
```