# `GET` /api/users/:id/likes
<!-- 一級標題自動成為筆記名稱 -->
## API 功能
取得某位使用者按讚(喜歡)的推文。
* 需註冊才可進入。
* 回傳某位使用者的like資料。
* 資料依照like成立時間排序(由新到舊)。
* 每筆like資料中包含
* 該筆like的原tweet的資料(id, description, createdAt, replyCount, likeCount)、tweet的作者資料(id, name, account, avatar)
* 目前使用者(req.user)是否按讚該則推文(isLiked)
## 前端傳入資料
### query string
分頁功能 (optional)
| name | description | default |
| ------- | -------------------------| ------- |
| `count` | 一次取的資料筆數/每頁資料筆數 | null |
| `page` | 頁數 | null |
### parameters
params | Description
--- | ---
`id` | 欲查詢like的user id
### req.body
None
## 後端回傳資料
### 成功
```json
// status code: 200
[
{
"id": 4,
"TweetId": 2,
"createdAt": "2022-07-30T14:24:25.000Z", // like created time, sorting by this value
"Tweet": {
"id": 2,
"description": "balabala",
"createdAt": "2022-06-30T17:37:30.000Z", // tweet created time
"likeCount": 4,
"replyCount": 3,
"User": { // tweet author
"id": 2,
"name": "user1",
"account": "user1",
"avatar": "https://avatar-url"
}
},
"isLiked": true // if the current user (req.user) is like the tweet
},
{
"id": 14,
"TweetId": 7,
"createdAt": "2022-07-30T14:24:25.000Z",
"Tweet": {
"id": 7,
"description": "balabababa",
"createdAt": "2022-07-17T20:08:40.000Z",
"likeCount": 5,
"replyCount": 3,
"User": {
"id": 2,
"name": "user1",
"account": "user1",
"avatar": "https://avatar-url"
}
},
"isLiked": true
},
// ...more likes
]
```
### 失敗
發生原因:使用者 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`