# `GET` /api/users/:id/tweets ## API 功能 取得單一使用者的所有推文。 * 使用者role為user才可進入。 * 回傳指定單一使用者的所有tweets。 * 資料依照tweet成立時間排序(由新到舊)。 * 每筆tweet資料中包含 * tweet的作者資料(id, name, account, avatar) * tweet的like數量(likeCount) * tweet的reply數量(replyCount) * 目前使用者是否like這則推文(isLiked) ## 前端傳入資料 ### query string 分頁功能 (optional) | name | description | default | | ------- | -------------------------| ------- | | `count` | 一次取的資料筆數/每頁資料筆數 | null | | `page` | 頁數 | null | ### parameters params | Description --- | --- `id` | 欲查詢tweets的作者user id ### req.body N/A (使用req.user.id看目前使用者id) ## 後端回傳資料 ### 驗證成功 ```json // status code: 200 // return an Array [ { "id": 4, "description": "balabala", "createdAt": "2022-07-29T13:02:03.000Z", "replyCount": 3, "likeCount": 2, "User": { "id": 2, "name": "user1", "account": "user1", "avatar": "https://avatar-url" }, "isLiked": true }, { "id": 8, "description": "balabababa", "createdAt": "2022-07-21T19:33:12.000Z", "replyCount": 3, "likeCount": 0, "User": { "id": 2, "name": "user1", "account": "user1", "avatar": "https://avatar-url" }, "isLiked": false }, // ...more tweets ] ``` ### 失敗 發生原因:使用者 token 驗證不通過。 ```javascript // status code: 401 { "status": "error", "message": "Unauthorized. Please login first." } ``` 發生原因:找不到與傳入 `id` 對應的 user。 ```javascript // status code: 404 { "status": "error", "message": "User is not found" } ``` ## 相關連結 * [回首頁](https://hackmd.io/@twitter-2022/index) * [API 總表](/Gl56cI2LQ5ObBpmQnbnphw) ###### tags: `API-doc`