User API

使用者能編輯自己的 account、name、email 和 password

PUT hostname/api/users/:id/setting

Path Parameters

Request Body

{
    "status": "success",
    "message": "修改成功",
    "data": {
        "name": "user1123",
        "account": "us23r11223",
        "email": "us2r1@example.com"
    }
}

取得當前登入者個人資料

GET hostname/api/current_user

{
    "status": "success",
    "message": "成功獲取",
    "data": {
        "id": 2,
        "account": "user1",
        "email": "user1@example.com",
        "name": "user1",
        "avatar": "https://loremflickr.com/240/240?lock=30.005523637159648",
        "role": "user",
        "cover": "https://loremflickr.com/720/240?lock=89.83133257495717",
        "followerCount": 0,
        "followingCount": 0,
        "tweetCount": 10,
        "isExpiredToken": false
    }
}

獲取前十名followers較多的使用者

GET hostname/api/users/top

{
    "status": "success",
    "message": "成功獲取",
    "data": [
        {
            "id": 3,
            "name": "user2",
            "avatar": "https://loremflickr.com/240/240?lock=70.5829761695203",
            "account": "user2",
            "followerCount": 2,
            "Followers": [
                {
                    "id": 2,
                    "account": "user1",
                    "email": "user1@example.com",
                    "name": "user1",
                    "avatar": "https://loremflickr.com/240/240?lock=30.005523637159648",
                    "cover": "https://loremflickr.com/720/240?lock=89.83133257495717",
                    "introduction": "rerum",
                    "role": "user",
                    "likeCount": 0,
                    "tweetCount": 10,
                    "followingCount": 0,
                    "followerCount": 0,
                    "createdAt": "2022-02-25T22:18:10.000Z",
                    "updatedAt": "2022-02-25T22:18:10.000Z",
                    "Followship": {
                        "id": 1,
                        "followerId": 2,
                        "followingId": 3,
                        "createdAt": "2022-02-25T22:18:10.000Z",
                        "updatedAt": "2022-02-25T22:18:10.000Z"
                    }
                },
                {
                    "id": 4,
                    "account": "user3",
                    "email": "user3@example.com",
                    "name": "user3",
                    "avatar": "https://loremflickr.com/240/240?lock=15.352250709560565",
                    "cover": "https://loremflickr.com/720/240?lock=97.46697388063966",
                    "introduction": "quae dolorum non",
                    "role": "user",
                    "likeCount": 0,
                    "tweetCount": 10,
                    "followingCount": 0,
                    "followerCount": 1,
                    "createdAt": "2022-02-25T22:18:10.000Z",
                    "updatedAt": "2022-02-25T22:18:10.000Z",
                    "Followship": {
                        "id": 3,
                        "followerId": 4,
                        "followingId": 3,
                        "createdAt": "2022-02-25T22:18:10.000Z",
                        "updatedAt": "2022-02-25T22:18:10.000Z"
                    }
                }
            ],
            "isFollowed": true
        },
        {
            "id": 4,
            "name": "user3",
            "avatar": "https://loremflickr.com/240/240?lock=15.352250709560565",
            "account": "user3",
            "followerCount": 1,
            "Followers": [
                {
                    "id": 2,
                    "account": "user1",
                    "email": "user1@example.com",
                    "name": "user1",
                    "avatar": "https://loremflickr.com/240/240?lock=30.005523637159648",
                    "cover": "https://loremflickr.com/720/240?lock=89.83133257495717",
                    "introduction": "rerum",
                    "role": "user",
                    "likeCount": 0,
                    "tweetCount": 10,
                    "followingCount": 0,
                    "followerCount": 0,
                    "createdAt": "2022-02-25T22:18:10.000Z",
                    "updatedAt": "2022-02-25T22:18:10.000Z",
                    "Followship": {
                        "id": 2,
                        "followerId": 2,
                        "followingId": 4,
                        "createdAt": "2022-02-25T22:18:10.000Z",
                        "updatedAt": "2022-02-25T22:18:10.000Z"
                    }
                }
            ],
            "isFollowed": true
        },
        {
            "id": 2,
            "name": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=30.005523637159648",
            "account": "user1",
            "followerCount": 0,
            "Followers": [],
            "isFollowed": false
        },
        .
        .
}

登入使用者

POST hostname/api/login

Request Body

{ 
    "status": "success",
    "token": string, 
    "data": { 
        "id": integer,
        "name": string,
        "email": string,
        "account": string,
        "password": string,
        "role": "user",
        "introduction": string,
        "avatar": string,
        "cover": string,
        "tweet_count": integer,
        "follower_count": integer,
        "following_count": integer,
        "like_count": integer,
        "updated_at": timestamp,
        "created_at": timestamp
    }, 
    "message": null 
}

註冊使用者

POST hostname/api/users

Request Body

{
    "status": "success",
    "message": "註冊成功",
    "data": {
        "likeCount": 0,
        "tweetCount": 0,
        "followingCount": 0,
        "followerCount": 0,
        "id": 24,
        "name": "user1",
        "account": "user12345",
        "email": "user12345@example.com",
        "role": "user",
        "avatar": "https://res.cloudinary.com/dqfxgtyoi/image/upload/v1644154630/github/defaultAvatar_uapauy.png",
        "cover": "https://res.cloudinary.com/dqfxgtyoi/image/upload/v1645696452/github/defaultCover_uhyyds.jpg",
        "updatedAt": "2022-02-27T20:30:54.609Z",
        "createdAt": "2022-02-27T20:30:54.609Z"
    }
}

獲取指定使用者的個人資料

GET hostname/api/users/:id

Path Parameters

{
    "status": "success",
    "message": "修改成功",
    "data": {
        "id": 3,
        "account": "user2",
        "email": "user2@example.com",
        "name": "556699erewrwre",
        "avatar": "0",
        "cover": "0",
        "introduction": "8799",
        "role": "user",
        "likeCount": 0,
        "tweetCount": 10,
        "followingCount": 0,
        "followerCount": 0,
        "createdAt": "2022-02-26T18:10:09.000Z",
        "updatedAt": "2022-02-26T22:56:41.000Z"
    }
}

獲取使用者寫過的所有推文

GET hostname/api/users/:id/tweets

Path Parameters

[
    {
        "id": 1,
        "UserId": 2,
        "description": "Voluptatem repellendus tenetur quis. Vel eveniet saepe exercitationem. Delectus beatae amet dolor nulla et consectetur veniam. Qui distincti",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 2,
        "UserId": 2,
        "description": "Ab eos est quas ut et quo tenetur. Eum quia doloremque iure. Eos harum illo possimus quaerat est.",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 3,
        "UserId": 2,
        "description": "quam sed architecto",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 4,
        "UserId": 2,
        "description": "Aut quo odio in nobis. Sit quisquam quam aut. Ullam et perspiciatis odio ratione. Ut maxime eveniet non facere quasi autem facilis.",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 5,
        "UserId": 2,
        "description": "Et autem qui non.",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 6,
        "UserId": 2,
        "description": "Laborum dolor fugit ea sunt et et temporibus.\nRecusandae nihil quis velit.\nRepellendus ullam atque expedita voluptatem voluptatem saepe dolo",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 7,
        "UserId": 2,
        "description": "Voluptates optio assumenda vel sit eos praesentium. Et pariatur consequatur eum et consectetur eius consequatur. Hic rerum aut facilis fugit",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 8,
        "UserId": 2,
        "description": "Quia dolorem minima deserunt ipsam et.",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 9,
        "UserId": 2,
        "description": "Rem consequuntur eaque voluptate officiis nesciunt provident ea facilis ea. Molestias aut ut est. Laborum aliquam consequuntur aperiam cupid",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    },
    {
        "id": 10,
        "UserId": 2,
        "description": "Tempore velit temporibus aut harum nisi iusto.",
        "createdAt": "2022-02-26T23:25:09.000Z",
        "updatedAt": "2022-02-26T23:25:09.000Z",
        "likeCount": 0,
        "replyCount": 3,
        "TweetAuthor": {
            "id": 2,
            "name": "user1",
            "account": "user1",
            "avatar": "https://loremflickr.com/240/240?lock=93.62407901541158"
        }
    }
]

獲取對應使用者所回覆的推文(包含回覆內容,會標記哪些推文是目前使用者喜歡和回覆)

GET hostname/api/users/:id/replied_tweets

Path Parameters

[
    {
        "id": 41,
        "UserId": 3,
        "TweetId": 14,
        "comment": "Nesciunt rerum et.\nAnimi qui ut suscipit earum vitae eius doloribus voluptatem qui.\nVeritatis ad et qui nisi sed voluptate.\nTemporibus nihil",
        "createdAt": "2022-03-03T23:29:03.000Z",
        "updatedAt": "2022-02-26T20:29:03.000Z",
        "isLikedTweet": false,
        "isRepliedTweet": true,
        "ReplyAuthor": {
            "id": 3,
            "account": "user2",
            "name": "user2",
            "cover": "https://loremflickr.com/720/240?lock=93.3205333349494",
            "avatar": "https://loremflickr.com/240/240?lock=53.35063209756541"
        },
        "TargetTweet": {
            "id": 14,
            "UserId": 2,
            "description": "Blanditiis qui labore ex aspernatur.",
            "likeCount": 0,
            "replyCount": 3,
            "createdAt": "2022-02-26T20:29:03.000Z",
            "updatedAt": "2022-02-26T20:29:03.000Z",
            "TweetAuthor": {
                "id": 2,
                "name": "user1",
                "account": "user1",
                "avatar": "https://loremflickr.com/240/240?lock=3.5899861119462297",
                "cover": "https://loremflickr.com/720/240?lock=81.9795525651643"
            }
        }
    },
    {
        "id": 56,
        "UserId": 3,
        "TweetId": 19,
        "comment": "dignissimos rem fugiat",
        "createdAt": "2022-03-03T20:29:03.000Z",
        "updatedAt": "2022-02-26T20:29:03.000Z",
        "isLikedTweet": true,
        "isRepliedTweet": true,
        "ReplyAuthor": {
            "id": 3,
            "account": "user2",
            "name": "user2",
            "cover": "https://loremflickr.com/720/240?lock=93.3205333349494",
            "avatar": "https://loremflickr.com/240/240?lock=53.35063209756541"
        },
        "TargetTweet": {
            "id": 19,
            "UserId": 2,
            "description": "Facilis quo a est enim a molestiae. Iure eos totam nihil. Voluptatum dolor vero omnis at provident.\n \rEt sed vero. Omnis commodi molestiae s",
            "likeCount": 0,
            "replyCount": 3,
            "createdAt": "2022-02-26T20:29:03.000Z",
            "updatedAt": "2022-02-26T20:29:03.000Z",
            "TweetAuthor": {
                "id": 2,
                "name": "user1",
                "account": "user1",
                "avatar": "https://loremflickr.com/240/240?lock=3.5899861119462297",
                "cover": "https://loremflickr.com/720/240?lock=81.9795525651643"
            }
        }
    },
    {
        "id": 46,
        "UserId": 3,
        "TweetId": 16,
        "comment": "dicta unde et",
        "createdAt": "2022-03-02T22:29:03.000Z",
        "updatedAt": "2022-02-26T20:29:03.000Z",
        "isLikedTweet": false,
        "isRepliedTweet": false,
        "ReplyAuthor": {
            "id": 3,
            "account": "user2",
            "name": "user2",
            "cover": "https://loremflickr.com/720/240?lock=93.3205333349494",
            "avatar": "https://loremflickr.com/240/240?lock=53.35063209756541"
        },
        "TargetTweet": {
            "id": 16,
            "UserId": 2,
            "description": "quas",
            "likeCount": 0,
            "replyCount": 3,
            "createdAt": "2022-02-26T20:29:03.000Z",
            "updatedAt": "2022-02-26T20:29:03.000Z",
            "TweetAuthor": {
                "id": 2,
                "name": "user1",
                "account": "user1",
                "avatar": "https://loremflickr.com/240/240?lock=3.5899861119462297",
                "cover": "https://loremflickr.com/720/240?lock=81.9795525651643"
            }
        }
    },
    .
    .
]

獲取對應使用者所喜歡的所有推文(標記目前推文是否被登入者喜歡或者回覆過)

GET hostname/api/users/:id/likes

Path Parameters

[
    {
        "id": 4,
        "UserId": 2,
        "TweetId": 2,
        "createdAt": "2022-02-27T19:15:24.000Z",
        "updatedAt": "2022-02-27T19:15:24.000Z",
        "LikedTweet": {
            "id": 2,
            "UserId": 3,
            "description": "quia architecto voluptas",
            "createdAt": "2022-02-27T19:15:24.000Z",
            "updatedAt": "2022-02-27T19:15:24.000Z",
            "replyCount": 3,
            "likeCount": 3,
            "isLiked": true,
            "isReplied": false,
            "TweetAuthor": {
                "id": 3,
                "account": "user2",
                "name": "user2",
                "email": "user2@example.com",
                "avatar": "https://loremflickr.com/240/240?lock=72.43383079474094",
                "cover": "https://loremflickr.com/720/240?lock=10.63680700768441"
            }
        }
    },
    {
        "id": 7,
        "UserId": 2,
        "TweetId": 3,
        "createdAt": "2022-02-27T19:15:24.000Z",
        "updatedAt": "2022-02-27T19:15:24.000Z",
        "LikedTweet": {
            "id": 3,
            "UserId": 3,
            "description": "Vero hic asperiores expedita et.",
            "createdAt": "2022-02-27T19:15:24.000Z",
            "updatedAt": "2022-02-27T19:15:24.000Z",
            "replyCount": 3,
            "likeCount": 3,
            "isLiked": true,
            "isReplied": false,
            "TweetAuthor": {
                "id": 3,
                "account": "user2",
                "name": "user2",
                "email": "user2@example.com",
                "avatar": "https://loremflickr.com/240/240?lock=72.43383079474094",
                "cover": "https://loremflickr.com/720/240?lock=10.63680700768441"
            }
        }
    },
    .
    .
]

看見某使用者跟隨中的人(會標記哪些使用者是目前使用者所追隨的)

GET hostname/api/users/:id/followings

Path Parameters

[
    {
        "followingId": 4,
        "name": "user3",
        "account": "user3",
        "introduction": "Excepturi porro quis ex consequatur eos voluptates. Nulla hic sunt dolor atque repellat aut. Numquam quibusdam earum natus a consequatur. Eos tempore modi volup",
        "cover": "https://loremflickr.com/720/240?lock=68.61269720187437",
        "avatar": "https://loremflickr.com/240/240?lock=86.7250929413381",
        "isFollowed": true,
        "Followship": {
            "id": 2,
            "followerId": 3,
            "followingId": 4,
            "createdAt": "2022-02-28T15:25:04.000Z",
            "updatedAt": "2022-02-28T15:25:04.000Z"
        }
    },
    {
        "followingId": 5,
        "name": "user4",
        "account": "user4",
        "introduction": "eum aut asperiores",
        "cover": "https://loremflickr.com/720/240?lock=2.113564844736392",
        "avatar": "https://loremflickr.com/240/240?lock=23.357860923180617",
        "isFollowed": false,
        "Followship": {
            "id": 3,
            "followerId": 3,
            "followingId": 5,
            "createdAt": "2022-02-27T15:25:04.000Z",
            "updatedAt": "2022-02-27T15:25:04.000Z"
        }
    },
    {
        "followingId": 6,
        "name": "user5",
        "account": "user5",
        "introduction": "maxime maxime iste",
        "cover": "https://loremflickr.com/720/240?lock=79.92451816607537",
        "avatar": "https://loremflickr.com/240/240?lock=73.34417809356532",
        "isFollowed": false,
        "Followship": {
            "id": 4,
            "followerId": 3,
            "followingId": 6,
            "createdAt": "2022-02-26T15:25:04.000Z",
            "updatedAt": "2022-02-26T15:25:04.000Z"
        }
    }
]

看見某使用者的跟隨者(會標記哪些使用者是目前使用者所追隨的)

GET hostname/api/users/:id/followers

Path Parameters

[
    {
        "followerId": 9,
        "name": "user2",
        "account": "user2",
        "introduction": "Veniam porro sapiente.\nPerferendis non aliquid earum aspernatur atque vel unde beatae.\nQuia ex facere.\nVel consequatur iusto ab.\nEum at numquam ipsum magnam et ",
        "cover": "https://loremflickr.com/720/240?lock=100.59738129015452",
        "avatar": "https://loremflickr.com/240/240?lock=20.16533509754197",
        "isFollowed": true,
        "Followship": {
            "id": 2,
            "followerId": 9,
            "followingId": 10,
            "createdAt": "2022-02-28T15:56:08.000Z",
            "updatedAt": "2022-02-28T15:56:08.000Z"
        }
    },
    {
        "followerId": 8,
        "name": "user1",
        "account": "user1",
        "introduction": "Fugit ut quaerat voluptatem consequatur sunt. Qui molestiae rerum natus assumenda non. Cumque non amet placeat quo reiciendis et laudantium omnis modi. Expedita",
        "cover": "https://loremflickr.com/720/240?lock=17.75232230027939",
        "avatar": "https://loremflickr.com/240/240?lock=81.76069650320224",
        "isFollowed": false,
        "Followship": {
            "id": 1,
            "followerId": 8,
            "followingId": 10,
            "createdAt": "2022-02-26T15:56:08.000Z",
            "updatedAt": "2022-02-26T15:56:08.000Z"
        }
    },
    {
        "followerId": 11,
        "name": "user4",
        "account": "user4",
        "introduction": "Et id sint. Laborum non velit autem facilis est inventore. Nemo inventore ut enim unde voluptatem. Ut excepturi maxime non eius est expedita laudantium iste. Am",
        "cover": "https://loremflickr.com/720/240?lock=39.44557003313784",
        "avatar": "https://loremflickr.com/240/240?lock=37.77200372061999",
        "isFollowed": false,
        "Followship": {
            "id": 3,
            "followerId": 11,
            "followingId": 10,
            "createdAt": "2022-02-25T15:56:08.000Z",
            "updatedAt": "2022-02-25T15:56:08.000Z"
        }
    }
]

更新個人資料表單(可上傳圖片、封面、更新自我介紹/暱稱)

PUT hostname/api/users/:id

Path Parameters

Request Body

{
    "status": "success",
    "message": "修改成功",
    "data": {
        "account": "us23r11223",
        "name": "123",
        "introduction": "HII",
        "avatar": "https://i.imgur.com/bD2jgsY.png",
        "cover": "https://i.imgur.com/5lNMek9.png"
    }
}

Last updated