# `POST` /api/followships ## API 功能 新增一筆追蹤關係。 * 登入者必須是 user。 ## 邏輯分析(後端看的) :::spoiler 運作邏輯 1. 新增者必須登入且身分是 user 2. 檢查傳入資料(是否為空值?) 3. 資料庫搜尋(若找不到則回傳錯誤訊息) 5. 不可重複追蹤、不可追蹤自己。 ::: :::spoiler [測試檔 pass](https://github.com/ritachien/twitter-api-2022/blob/main/test/requests/admin.spec.js#L88-L105) ::: :::spoiler 人工測試(3/3) - [x] 使用 admin 帳號顯示錯誤訊息。 - [x] 前端提供資料欄位缺失顯示錯誤訊息。 - [x] 刪除完成回傳稱成功訊息。 ::: ## 前端傳入資料 ### parameters None ### req.body |name|description| |---|---| |`id`| 要被追蹤的 user `id` | ## 後端回傳資料 ### 驗證成功 ```javascript // status code: 200 { "status": "success", "message": "Start following" } ``` ### 傳入資料格式有誤 發生原因: 檢查後發現任一欄位為空。 ```json // status code: 400 { "status": "error", "message": "followerId and followingId required" } ``` ### 檢查失敗 發生原因: 不能追蹤自己。 ```javascript // status code: 401 { "status": "error", "message": "Can not follow yourself" } ``` 發生原因: 不能重複追蹤。 ```javascript // status code: 401 { "status": "error", "message": "Can not follow user who is already being followed" } ``` ## 相關連結 * [回首頁](https://hackmd.io/@twitter-2022/index) * [API 總表](/Gl56cI2LQ5ObBpmQnbnphw) ###### tags: `API-doc`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up