---
# System prepended metadata

title: DAYEAYEAYEA - API 文件 (施工中)
tags: [期末專案]

---

# DAYEAYEAYEA - API 文件 (施工中)
###### tags: `期末專案`


## URL Path Documentation
> `https://api.coolizz.tw`
> 
### Root Path：`/api/v1`
* /v1/members
* /v1/products
* /v1/orders
* /v1/articles
* /v1/faq


### 會員 members

| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 註冊    | POST     | /members/register     | 
| 登入     | POST     | /members/login     |
| 取得所有會員資料     | GET     | /members     |
| 取得單一會員資料     | GET     | /members/:id     |
| 修改單一會員資料     | PATCH     | /members/:id     |
| ~~刪除單一會員資料~~     | DELETE     | /members/:id     |




### 商品 products

| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 取得所有商品     | GET     | /products     | 
| 搜尋商品     | GET     | /products?search=`keyword`     |
| 取得單一商品     | GET     | /products/:id     |
| 取得分類商品     | GET     | /products/category/:category     |
| 取得精選文章商品     | GET     | /products/article/:article     |
| 新增商品     | POST     | /products/new*    | 
| 編輯商品 (軟刪除用這個)     | PATCH     | /products/:id     |
| 刪除商品    | DELETE     | /products/:id     |



### 訂單 orders
> 所以登入才能訪問, 只能取得自己的

| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 取得所有訂單     | GET     | /orders     |
| 取得單筆訂單     | GET     | /orders/:id     |
| 取得自己的全部訂單     | GET     | /orders/me     |
| 取得自己的單筆訂單     | GET     | /orders/me/id     |
| 建立訂單     | POST     | /orders     |
| 編輯訂單     | PATCH     | /orders/:id     |
| 編輯訂單(處理中)     | PATCH     | /orders/:id/noraml     |
| 編輯訂單(已取消)      | PATCH     | /orders/:id/cancel     |
| 編輯訂單(已出貨)      | PATCH     | /orders/:id/ship     |
| 編輯訂單(已完成)      | PATCH     | /orders/:id/complete     |
| 刪除訂單     | DELETE     | /orders/:id     |


### P2 訂單留言板 messages

| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 取得訂單留言     | GET     | /orders/:id/messages     |
| 新增訂單留言     | POST     | /orders/:id/messages     |
| 編輯訂單留言     | PATCH     | /orders/:id/messages     |
| 刪除訂單留言     | PATCH     | /orders/:id/messages     |

### 精選文章 articles

| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 取得所有文章     | GET     | /articles     |
| 取得單篇文章     | GET     | /articles/:id     |

註：因為目前不打算在後台做文章管理系統，所以文章要到資料庫手動改，API 先寫兩支拿資料的就好。

### 常見問題 faq
| 說明 | Method | Path | 參數 |
| -------- | -------- | -------- | -------- |
| 取得所有問答     | GET     | /faq     |


## Request & Response 範例

> 編輯、新增 & 刪除的 request 會長怎樣？

### 會員 members
**註冊：**
```json
// request
{
    "username": "jackie",
    "password": "7788",
    "email": "jj@gmail.com"
}
```
```json
// 成功 response
{
    "ok": 1,
}
// 失敗 response
{
    "ok": 0,
    "errMsg": "fail"
}
```
**登入：**

```json
// request
{
    "username": "jackie",
    "password": "7788"
}
```
```json
// response
{
    "ok": 1,
}
```
**登出：**
```json
// response
{
    "ok": 1,
}
```
**取得自己的會員資料：**
```json
// response
{
    "ok": 1,
    "data": {
        "id": 1,
        "username": "jackie",
        "fullname": "柳承智",
        "email": "jj@gmail.com", 
        "phone": "0912345678",
        "address": "台北市中正區羅斯福路二段188號2樓",
        "level": "VIP"
    }
}
```
**修改自己的會員資料：**
```json
// request
{
    "fullname": "柳承汁",
    "email": "jjjjj@gmail.com", 
    "phone": "0987654321",
    "address": "台北市中正區羅斯福路二段188號5樓"
}
```
```json
// response
{
    "ok": 1,
    "msg": "success"
}
```
**取得所有會員資料：**
```json
// response
{
    "ok": 1,
    "data": [
        {
            "id": 1,
            "username": "jackie",
            "fullname": "柳承智",
            "email": "jj@gmail.com", 
            "phone": "0912345678",
            "address": "台北市中正區羅斯福路二段188號2樓",
            "level": "VIP"
        },
        {
            "id": 2,
            "username": "todd",
            "fullname": "陶德",
            "email": "todd@gmail.com", 
            "phone": "0911111111",
            "address": "台北市中正區羅斯福路一段1號1樓",
            "level": "normal"
        }
    ]
}
```
**取得單一會員資料：**
```json
// response
{
    "ok": 1,
    "data": {
        "id": 2,
        "username": "todd",
        "fullname": "陶德",
        "email": "todd@gmail.com", 
        "phone": "0911111111",
        "address": "台北市中正區羅斯福路一段1號1樓",
        "level": "normal"
    }
}
```
### 商品 products

**取得所有商品：**

```json
// response
{
    "ok": 1,
    "data": [
        {
            "id": 1,
            "category": "kitchen",
            "articles": null,
            "name": "日本 YAMADA 復古咖啡磨豆機",
            "price": 4200,
            "discount_price": null,
            "quantity": 2,
            "status": "ON", //在架上
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z",
            "isDeleted": null
        },
        {
            "id": 2,
            "category": "home",
            "articles": "香氛",
            "name": "Fragrance 香氛蠟燭 - 柚木 & 菸草/7.2oz",
            "price": 980,
            "discount_price": 799,
            "quantity": 10,
            "status": "ON", //在架上
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/UkpoukZ.jpg",
                "https://i.imgur.com/UkpoukZ.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z",
            "isDeleted": null
        },
        .
        .
        .
    ]
}
```

**取得單一商品：**
```json
// response
{
    "ok": 1,
    "data":
        {
            "id": 1,
            "category": "kitchen",
            "articles": null,
            "name": "日本 YAMADA 復古咖啡磨豆機",
            "price": 4200,
            "discount_price": null,
            "quantity": 2,
            "status": "ON", //在架上
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z",
            "isDeleted": null
        }
}
```

**搜尋商品 & 取得分類商品 & 取得精選文章商品：**


```json
// response
{
    "ok": 1,
    "data": [
        {
            "id": 2,
            "category": "home",
            "articles": "香氛",
            "name": "Fragrance 香氛蠟燭 - 柚木 & 菸草/7.2oz",
            "price": 980,
            "discount_price": 799,
            "quantity": 10,
            "status": "ON", //在架上
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/UkpoukZ.jpg",
                "https://i.imgur.com/UkpoukZ.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z",
            "isDeleted": null
        },
        {
            "id": 5,
            "category": "home",
            "articles": "香氛",
            "name": "Fragrance 香氛蠟燭 - 黃金海岸/7.2oz",
            "price": 980,
            "discount_price": 799,
            "quantity": 12,
            "status": "ON", //在架上
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/UkpoukZ.jpg",
                "https://i.imgur.com/UkpoukZ.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z",
            "isDeleted": null
        },
        .
        .
    ]
}
```

**新增商品：**
```json
// response
{
    "ok": 1,
    "msg": "success"
}
```
**編輯商品：**
```json
// resquest
{
    "ok": 1,
    "data":
        {
            "category": "kitchen",
            "name": "日本 YAMADA 復古咖啡磨豆機",
            "price": 4200,
            "quantity": 1, // 賣掉一個
            "status": "ON",
            "short_desc": "短敘述",
            "long_desc": "長敘述",
            "imgs": [
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg",
                "https://i.imgur.com/uv6hhGR.jpg"
            ],
            "created_at": "2020-12-01T02:24:30.000Z"
            "isDeleted": null
        }
}
```

```json
// response
{
    "ok": 1,
    "msg": "success"
}
```

刪除商品*：
```json
// response
{
    "ok": 1,
    "msg": "success"
}
```

### 訂單 orders

**取得單筆訂單：**
```json
// response
{
    "ok": 1,
    "data": {
        "id": 1,
        "memberId": 1,
        "total_price": 6160,
        "status": "處理中",
        "order_address": "台北市北投區行義路198巷1樓", // 資料庫要改 ?
        "order_name": "劉叮叮",
        "order_email": "jj@gmail.com",
        "order_phone": "0912345678",
        "member": {
            "memberId": 1,
            "usename": 'jackie',
            "fullname": '柳承智',
            "email": 'jj@gmail.com',
            "phone": "0912345678",
            "address": "台北市中正區羅斯福路二段188號2樓"
        }
        "items": [
            {
                "ProductId": 1
                "name": "Fragrance 香氛蠟燭 - 柚木 & 菸草/7.2oz",
                "price": 980,
                "quantity": 2,
                "img": URL

            },
            {
                "ProductId": 1
                "name": "日本 YAMADA 復古咖啡磨豆機",
                "price": 4200,
                "quantity": 1,
                "img": URL
            }
        ],
        "created_at": "2020-12-01T02:24:30.000Z"
    }
}
```
**取得自己的訂單：**
```json
// response
{
    "ok": 1,
    "data": [
        {
            "id": 1,
            "memberId": 1,
            "total_price": 6160,
            "status": "處理中",
            "order_address": "台北市北投區行義路198巷1樓", // 資料庫要改 ?
            "order_name": "劉叮叮",
            "order_email": "jj@gmail.com",
            "order_phone": "0912345678",
            "member": {
                "memberId": 1,
                "usename": 'jackie',
                "fullname": '柳承智',
                "email": 'jj@gmail.com',
                "phone": "0912345678",
                "address": "台北市中正區羅斯福路二段188號2樓"
            }
            "items": [
                {
                    "name": "Fragrance 香氛蠟燭 - 柚木 & 菸草/7.2oz",
                    "price": 980,
                    "quantity": 2,

                },
                {
                    "name": "日本 YAMADA 復古咖啡磨豆機",
                    "price": 4200,
                    "quantity": 1,
                }
            ],
            "created_at": "2020-12-01T02:24:30.000Z"
        }, 
        {
         // 第二筆訂單
        },
        .
        .
        .
        
    ]
}
```
**建立訂單：**
刪除訂單*：
**取消訂單：**
**訂單出貨：**
**完成訂單：**

### 訂單留言板 messages(P2)：
**取得訂單留言：**
**新增訂單留言：**
**編輯訂單留言：**
**刪除訂單留言：**

### 精選文章 articles
**取得所有文章：**
```json
{
    "ok": 1,
    "data": [
        {
            "id": 1,
            "title": "",
            "content": "",
            "img": "",
            "created_at": ""
        },
        {
            "id": 2,
            "title": "",
            "content": "",
            "img": "",
            "created_at": ""
        },
        .
        .
        .
    ]
}
```
**取得單篇文章：**
```json
{
    "ok": 1,
    "data": {
        "id": 1,
        "title": "",
        "content": "",
        "img": "",
        "created_at": ""
    }
}
```
### 常見問題 faq

```json
// response
{
    ok: 1,
    data: [
      {
        id: 1,
        question: "一定要加入會員才能下單嗎？",
        answer:
          "對。為了方便您追蹤及管理訂單，請先加入會員再購買商品。",
      },
      {
        id: 2,
        question: "忘記密碼怎麼辦？",
        answer: "您可以點選登入頁面的「忘記密碼」，系統就會傳送變更密碼的 email 給您。",
      },
      {
        id: 3,
        question: "如何查詢我的訂單？",
        answer: "登入會員後，進入會員專區，即可在「我的訂單」查詢訂單詳細資訊。",
      },
      {
        id: 4,
        question: "我的商品什麼時候會送到？",
        answer: "您可以在會員專區的「訂單紀錄」中查看訂單狀態。一般情況下，我們會在 5-7 個工作天內出貨，而商品會在出貨後的 3-5 個工作天到貨。",
      },
      {
        id: 5,
        question: "如何辦理退貨？",
        answer: "不好意思，目前不提供退貨服務，請想清楚再購買，謝謝。",
      },
      {
        id: 6,
        question: "下錯訂單了怎麼辦？",
        answer: "送出訂單後，您可以前往會員專區的「訂單紀錄」頁面查詢您的訂單。只要尚未出貨，您都可以直接取消訂單。",
      },
      {
        id: 7,
        question: "我改名了，要去哪裡修改會員資料？",
        answer:  "真的嗎？希望是個吉利的好名字。回答您的問題，您可以在會員專區的「會員資料」中修改個人資料。",
      },
      {
        id: 8,
        question: "太好買買太多怎麼辦？",
        answer: "請多買一點，我們會幫您升級成 VIP 會員，讓您享有生日購物金、特定商品優惠價以及運費減免等眾多優惠。",
      },
    ];
}
```