# Admin API

## 後台登入管理員

<mark style="color:green;">`POST`</mark> `hostname/api/admin/login`

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| account<mark style="color:red;">\*</mark>  | String | 使用者帳號(登入用的) |
| password<mark style="color:red;">\*</mark> | String | 密碼          |

{% tabs %}
{% tab title="200: OK 獲取成功，回傳指定使用者資料" %}

```javascript
{ 
    "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": "登入成功"
}
```

{% endtab %}

{% tab title="400: Bad Request 請求參數有誤(有欄位沒填寫到)" %}

```
{
    "code" : 400,
    "status": "error", 
    "message": "所有欄位都要填寫"
}
```

{% endtab %}

{% tab title="500: Internal Server Error 系統出錯" %}

```javascript
{
    "code" : 500,
    "status": "error",
    "message": "系統出錯"
}
```

{% endtab %}

{% tab title="403: Forbidden 存取被拒(帳號不存在)" %}

```javascript
{
    "code" : 403,
    "status": "error", 
    "message": "帳號不存在"
}
```

{% endtab %}

{% tab title="403: Forbidden 存取被拒(帳號正確，但密碼錯誤)" %}

```javascript
{
    "code" : 403,
    "status": "error", 
    "message": "帳號或密碼錯誤"
}
```

{% endtab %}
{% endtabs %}

## 以管理員權限獲取全站的使用者

<mark style="color:blue;">`GET`</mark> `hostname/api/admin/users`

{% tabs %}
{% tab title="200: OK 獲取成功，以一組陣列來回傳全站的使用者" %}

```javascript
[
    {
        "id": 8,
        "account": "user1",
        "name": "user1",
        "avatar": "https://loremflickr.com/240/240?lock=95.39669124526131",
        "cover": "https://loremflickr.com/720/240?lock=40.54835105618357",
        "introduction": "Quod omnis natus animi ab tempore. Voluptatibus ut alias recusandae non cumque non quis laborum voluptatem. Sit quo beatae et voluptas corporis quam itaque adip",
        "followerCount": 0,
        "followingCount": 0,
        "likeCount": 0,
        "replyCount": 29
    },
    {
        "id": 9,
        "account": "user2",
        "name": "user2",
        "avatar": "https://loremflickr.com/240/240?lock=12.201137686513917",
        "cover": "https://loremflickr.com/720/240?lock=33.03304016856221",
        "introduction": "Praesentium facilis consequatur ea optio nisi iure.",
        "followerCount": 0,
        "followingCount": 0,
        "likeCount": 0,
        "replyCount": 35
    },
    .
    .
    .
]
```

{% endtab %}

{% tab title="401: Unauthorized 使用者未從登入驗證獲取憑證不予使用" %}

```
{
    "code" : 401,
    "status": "error", 
    "message": "使用者未從登入驗證獲取憑證不予使用"
}
```

{% endtab %}

{% tab title="500: Internal Server Error 系統出錯" %}

```javascript
{
    "code" : 500,
    "status": "error",
    "message": "系統出錯"
}
```

{% endtab %}

{% tab title="403: Forbidden 存取被拒" %}

```javascript
{
    "code" : 403,
    "status": "error", 
    "message": "存取被拒"
}
```

{% endtab %}
{% endtabs %}

## 刪除推文

<mark style="color:red;">`DELETE`</mark> `hostname/api/admin/tweets/:id`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| id   | String | 推文ID        |

{% tabs %}
{% tab title="200 刪除成功，回傳被刪除的貼文紀錄" %}

```javascript
{ 
    "status": "success",
    "message": "成功刪除貼文",
    "data": {
        "id": 2,
        "UserId": 2,
        "description": "Tenetur laboriosam commodi architecto suscipit quia accusantium aut expedita.",
        "likeCount": 0,
        "replyCount": 3,
        "createdAt": "2022-02-25T16:20:12.000Z",
        "updatedAt": "2022-02-25T16:20:12.000Z"
    }
}
```

{% endtab %}

{% tab title="401: Unauthorized 使用者未從登入驗證獲取憑證不予使用" %}

```
{
    "code" : 401,
    "status": "error", 
    "message": "使用者未從登入驗證獲取憑證不予使用"
}
```

{% endtab %}

{% tab title="500: Internal Server Error 系統出錯" %}

```javascript
{
    "code" : 500,
    "status": "error",
    "message": "系統出錯"
}
```

{% endtab %}

{% tab title="404: Not Found 對應推文不存在" %}

```javascript
{
    "code" : 404,
    "status": "error", 
    "message": "對應推文不存在"
}
```

{% endtab %}

{% tab title="403: Forbidden 存取被拒" %}

```javascript
{
    "code" : 403,
    "status": "error", 
    "message": "存取被拒"
}
```

{% endtab %}
{% endtabs %}

## 以管理員權限獲取全站的推文

<mark style="color:blue;">`GET`</mark> `hostname/api/admin/tweets`

{% tabs %}
{% tab title="200: OK 獲取成功，以一個陣列回傳全站的所有推文" %}

```javascript
[
    {
        "id": 1,
        "updatedAt": "2022-02-25T16:45:15.000Z",
        "description": "Debitis accusantium in dolore nemo quidem aut. Ass",
        "TweetAuthor": {
            "name": "user2",
            "account": "user2",
            "avatar": "https://loremflickr.com/240/240?lock=93.08216466743546"
        }
    },
    {
        "id": 3,
        "updatedAt": "2022-02-25T16:45:15.000Z",
        "description": "Ipsa illo sed voluptatibus blanditiis eum non.",
        "TweetAuthor": {
            "name": "user2",
            "account": "user2",
            "avatar": "https://loremflickr.com/240/240?lock=93.08216466743546"
        }
    },
    .
    .
]
```

{% endtab %}

{% tab title="401: Unauthorized 使用者未從登入驗證獲取憑證不予使用" %}

```
{
    "code" : 401,
    "status": "error", 
    "message": "使用者未從登入驗證獲取憑證不予使用"
}
```

{% endtab %}

{% tab title="500: Internal Server Error 系統出錯" %}

```javascript
{
    "code" : 500,
    "status": "error",
    "message": "系統出錯"
}
```

{% endtab %}

{% tab title="403: Forbidden 存取被拒" %}

```javascript
{
    "code" : 403,
    "status": "error", 
    "message": "存取被拒"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://simple-twitter-api.gitbook.io/api/HDZXvOJdS0oEs3mTdu7w/admin-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
