# `POST` /api/tweets/:tweet_id/replies <!-- 一級標題自動成為筆記名稱 --> ## API 功能 對一則貼文新增一則回覆。 * 需註冊才可進入,且role = user。 * 新增一則推文的一則回覆。 * 回覆內容限制:不可存入空資料或空白字串 ### 邏輯分析(後端看的) :::spoiler 運作邏輯 1. 取得req.req.params.tweet_id = TweetId,並檢查該則tweet是否存在 2. 取得req.user.id = UserId 3. 取得req.body.comment內容,檢查內容不可為空資料或空白字串 4. 將TweeId, UserId, comment在Reply中新增一筆資料 ::: ## 前端傳入資料 ### parameters params | Description --- | --- `tweet_id` | 欲新增回覆的tweet id ### req.body name | Description --- | --- `comment` | 回覆內容 ## 後端回傳資料 ### 成功 ```json // status code: 200 { "status": "success", "message": "Post reply successfully" } ``` ### 失敗 發生原因:使用者token驗證不通過。 ```javascript // status code: 401 { "status": "error", "message": "Unauthorized. Please login first." } ``` 發生原因:由傳入的tweet_id,資料庫找不到該筆tweet資料。 ```javascript // status code: 404 { "status": "error", "message": "Tweet is not found" } ``` 發生原因:沒有傳入tweet_id。 ```javascript // status code: 400 { "status": "error", "message": "TweetId is required" } ``` 發生原因:comment傳入空資料或空白字串。 ```javascript // status code: 400 { "status": "error", "message": "Reply is blank." } ``` ## 相關連結 * [回首頁](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