Index | Feature | HTTP Method | Route | Note |
---|---|---|---|---|
1 | 使用者註冊帳號 | POST | POST /api/users | account, name, email, password |
2 | 使用者登入 | POST | POST /api/users/signin | need authentication |
account, password | ||||
3 | 使用者可以看到自己的帳戶資料 | GET | GET /api/users/:id/setting | need authentication |
account, name, email, password | ||||
4 | 使用者可以編輯自己的帳戶資料 | PATCH | PATCH /api/users/:id/setting | need authentication |
account, name, email, password | ||||
5 | 使用者可以看到某使用者(包括自己)的個人資料 | GET | GET /api/users/:id | need authentication |
name, avatar, description, banner | ||||
6 | 使用者可以編輯自己的個人資料 | PUT | PUT /api/users/:id | need authentication |
name, avatar, description, banner | ||||
7 | 使用者可以看到某使用者(包括自己)的所有 tweets | GET | GET /api/users/:id/tweets | need authentication |
8 | 使用者看到某使用者(包括自己)回覆過的所有 tweets | GET | GET /api/users/:id/replied_tweets | need authentication |
9 | 使用者看到某使用者(包括自己)點擊過 like 的所有 tweets | GET | GET /api/users/:id/likes | need authentication |
10 | 使用者可以看到某使用者(包括自己)正在追蹤的人 | GET | GET /api/users/:id/followings | need authentication |
11 | 使用者(包括自己)可以看到某使用者被哪些人追蹤 | GET | GET /api/users/:id/followers | need authentication |
12 | 取得current user資訊 | GET | GET /api/get_current_user | need authentication |
HTTP Method : POST
Request Parameters:No
Request Body :註冊表單內的資料
Request Name | Type | Required | Example | |
---|---|---|---|---|
帳號 | account | STRING | True | 'Captain America' |
名稱 | name | STRING | True | 'Captain' |
STRING | True | '[email protected]' | ||
密碼 | password | STRING | True | 'youneverknow' |
密碼再次確認 | checkPassword | STRING | True | 'youneverknow' |
Success Response:
{
"status": "success"
}
Failure Response:
Status Code: 500
// 註冊表單上任何一個欄位是空白
{
"status": "error",
"message": "Error: All fields are required"
}
// 密碼和再次確認密碼不相同
{
"status": "error",
"message": "Error: "password" and "checkPassword" not matched"
}
// 帳號超過20個字
{
"status": "error",
"message": "Error: Characters length of account should be less than 20"
}
// 名字超過50個字
{
"status": "error",
"message": "Error: Characters length of name should be less than 50"
}
// 帳號已經被註冊過
{
"status": "error",
"message": "Error: The account has already been used by someone else"
}
// email 已經被註冊過
{
"status": "error",
"message": "Error: The email has already been used by someone else"
}
HTTP Method : POST
Request Parameters:No
Request Body :登入表單內的資料
Request Name | Type | Required | Example | |
---|---|---|---|---|
帳號 | account | STRING | True | 'Captain America' |
密碼 | password | STRING | True | 'youneverknow' |
Success Response:
{
"status": "success",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTUsImFjY291bnQiOiJ1c2VyMiIsIm5hbWUiOiJ1c2VyMiIsImVtYWlsIjoidXNlcjJAZXhhbXBsZS5jb20iLCJhdmF0YXIiOiJodHRwczovL2xvcmVtZmxpY2tyLmNvbS8zMjAvMjQwL3BhcmlzLGdpcmwvYWxsIiwiaW50cm9kdWN0aW9uIjoic2F5IHNvbWV0aGluZy4uIiwiYmFubmVyIjoiaHR0cHM6Ly9sb3JlbWZsaWNrci5jb20vMzIwLzI0MC9iZWFjaCIsInJvbGUiOiJ1c2VyIiwiY3JlYXRlZEF0IjoiMjAyMi0wOC0wMlQxMToyNTo1Ny4wMDBaIiwidXBkYXRlZEF0IjoiMjAyMi0wOC0wMlQxMToyNTo1Ny4wMDBaIiwiaWF0IjoxNjU5NDk3NTA0LCJleHAiOjE2NjA3MDcxMDR9.UmjpzseSMG3yOpdeq4DmVHE0Nk4PS9BAR5s4r6ejQWo"
}
Failure Response:
// 帳號或密碼錯誤
Status Code: 500
{
"status": "error",
"message": "Error: Account or Password error!"
}
// 使用者禁止登入管理者後台,管理者也禁止登入前台,視為帳號不存在
Status Code: 500
{
"status": "error",
"message": "Error: account not exist"
}
HTTP Method : GET
Request Parameters:No
Request Name | Type | Required | Example | |
---|---|---|---|---|
使用者 id | id | INTEGER | True | 1 |
Request Body :
Success Response:
{
"id": 3,
"account": "user20",
"name": "user20",
"email": "user20",
"avatar": "<https://loremflickr.com/320/240/paris,girl/all>",
"introduction": "say something..",
"banner": "<https://loremflickr.com/320/240/beach>",
"role": "user",
"createdAt": "2022-08-02T02:49:02.000Z",
"updatedAt": "2022-08-03T03:03:26.000Z"
}
Failure Response:
// 如果參數id檢查發現不是登入者
Status Code: 403
{
"status": "error",
"message": "Error: permission denied"
}
// 如果參數id資料庫找不到人
Status Code: 500
{
"status": "error",
"message": "Error: Target user not exist"
}