Enhance smoking tracking API and documentation

- Updated the main.go file to set the local time zone to Asia/Shanghai.
- Changed API endpoints from `PUT` to `POST` for user profile and logs management in multiple documentation files to reflect the correct usage.
- Added new fields in the API response for home summary, including `last_smoke_at`, `today_count`, `resisted_count`, and `reduced_from_yesterday`.
- Enhanced documentation across various files to accurately describe the updated API endpoints and their expected behaviors.
This commit is contained in:
nepiedg
2026-01-25 07:55:32 +00:00
parent be6d579d41
commit b67dc32369
12 changed files with 758 additions and 37 deletions
+26 -11
View File
@@ -155,7 +155,7 @@ curl -X GET 'http://127.0.0.1:8080/api/v1/smoke/logs/5202' \
## 6) 更新记录
`PUT /api/v1/smoke/logs/:id`
`POST /api/v1/smoke/logs/:id`
请求体(字段可选,按需传):
@@ -302,7 +302,7 @@ curl -X GET 'http://127.0.0.1:8080/api/v1/smoke/logs/5202' \
## 11) 补全/更新用户基础信息(Upsert)
`PUT /api/v1/smoke/profile`
`POST /api/v1/smoke/profile`
说明:
- 字段按需传;首次进入建议一次性补全。
@@ -348,6 +348,7 @@ curl -X GET 'http://127.0.0.1:8080/api/v1/smoke/logs/5202' \
说明:
- 用于首页展示“建议的下次记录时间”。
- 已整合首页所需汇总字段(上次抽烟时间/今日抽烟支数/今日克制次数/较昨日减少支数)。
- 如果指定日期存在 AI 给出的时间节点(`time_nodes` 不为空),则优先使用 AI 的建议;否则使用默认策略。
- 可选参数:
- `date`:计划日期(默认今天),支持 `YYYY-MM-DD``today/tomorrow`
@@ -372,18 +373,22 @@ AI 生成说明:
"message": "success",
"data": {
"source": "default",
"not_before_at": "2026-01-05T10:18:00+08:00",
"suggested_at": "2026-01-05T10:18:00+08:00",
"not_before_at": "2026-01-05 10:18:00",
"suggested_at": "2026-01-05 10:18:00",
"last_smoke_at": "2026-01-05 09:30:00",
"today_count": 3,
"resisted_count": 1,
"reduced_from_yesterday": 2,
"default": {
"last_smoke_at": "2026-01-05T09:30:00+08:00",
"next_smoke_at": "2026-01-05T10:18:00+08:00",
"last_smoke_at": "2026-01-05 09:30:00",
"next_smoke_at": "2026-01-05 10:18:00",
"base_interval_minutes": 48,
"interval_minutes": 48,
"stage": 0,
"resisted_7d": 3,
"sleep_adjusted": false,
"algorithm": "staircase_delay_v1",
"as_of": "2026-01-05T10:00:00+08:00"
"as_of": "2026-01-05 10:00:00"
}
}
}
@@ -396,15 +401,19 @@ AI 生成说明:
"message": "success",
"data": {
"source": "ai",
"not_before_at": "2026-01-05T10:18:00+08:00",
"suggested_at": "2026-01-05T10:28:00+08:00",
"not_before_at": "2026-01-05 10:18:00",
"suggested_at": "2026-01-05 10:28:00",
"last_smoke_at": "2026-01-05 09:30:00",
"today_count": 3,
"resisted_count": 1,
"reduced_from_yesterday": 2,
"time_nodes": ["10:30", "11:10", "14:00", "16:30"],
"advice": "先把这次冲动延后到10:28,期间做一次5分钟快走+喝水,压力场景用深呼吸替代。",
"default": { "algorithm": "staircase_delay_v1" },
"ai": {
"plan_date": "2026-01-05",
"not_before_at": "2026-01-05T10:18:00+08:00",
"suggested_at": "2026-01-05T10:28:00+08:00",
"not_before_at": "2026-01-05 10:18:00",
"suggested_at": "2026-01-05 10:28:00",
"time_nodes": ["10:30", "11:10", "14:00", "16:30"],
"advice": "先把这次冲动延后到10:28,期间做一次5分钟快走+喝水,压力场景用深呼吸替代。",
"prompt_version": "v1",
@@ -414,3 +423,9 @@ AI 生成说明:
}
}
```
字段说明(新增首页字段):
- `last_smoke_at`:上次“实际抽烟”时间(忽略忍住记录),格式 `YYYY-MM-DD HH:MM:SS`
- `today_count`:今日抽烟支数(累加 `num`)。
- `resisted_count`:今日克制次数(`level=0 && num=0`)。
- `reduced_from_yesterday`:较昨日减少的支数(`max(昨日支数 - 今日支数, 0)`)。