🎯 目標
加入 使用者帳號/登入系統(最小化版,不需要完整 OAuth)
在推薦 API 中考慮 個人化因子(年齡、性別、健康狀況、藥物清單、飲食偏好)
儲存使用者的查詢歷史與偏好,讓推薦結果能持續優化
🏗️ 技術設計
1. 使用者資料表設計
新增 users、user_profiles、user_preferences:
users: id, username, password_hash
user_profiles: user_id, age, gender, health_condition
user_preferences: user_id, favorite_foods, avoid_foods, current_drugs
2. 登入/註冊 API
/api/users/register
Request: { "username": "grace", "password": "1234" }
/api/users/login
Response: JWT token 或 session id
3. 個人化推薦 API
/api/recommendations/personalized?effectId=E002
從 JWT/session 找 user_id
帶入 user_profiles + user_preferences → 個人化計算
排除 avoid_foods,標記 current_drugs 交互作用
Response 範例:
4. 使用者歷史紀錄
新增 user_history 表:user_id, effect_id, query_time, result_count
未來可用於:
常查詢的效果 → 排序靠前
常被忽略的食材 → 降低權重
🧪 測試計畫
註冊/登入 → 拿到 token
使用 /api/recommendations/personalized 查詢 → 回傳個人化結果
測試不同使用者 → 推薦清單差異
驗證 avoid_foods、current_drugs → 正確過濾與警示
✅ 驗收標準
成功建立使用者帳號(能登入/註冊)
個人化 API 能根據使用者偏好/藥物清單給出不同推薦
查詢歷史能被儲存,未來可做排序優化