--- title: 'Member System & Shopping Cart API DOC' disqus: hackmd --- Member System & Shopping Cart API DOC === ## 目錄/Contents [TOC] ## 會員 member ### 註冊 register :::warning **POST** /api/member ::: | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | name(<font color = "#FD0000">required</font>) | String | x-www-form-urlencoded | 會員名稱 | | email(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 會員信箱 | | password(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 會員密碼 | --- :::warning Request ```json= { "name": "peter", //member name "email": "peter@gmail.com", //member email "password": "123" //member password } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "status": "Success", "result": { "registerMember": { "name": "peter", "email": "peter@gmail.com", "password": "df5df8f2a4d541d5q7w8d5d21f4g5e3s5c5ddfgh", //Encrypted password "created_date": "2021-09-25 17:09:57" } } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Email 格式錯誤 ```json= { "result": { "status": "Register fail", "err": "Please enter correct email format. (123@gmail.com)" } } ``` Response Error type: Email 已經註冊 ```json= { "result": { "status": "Register fail", "err": "Email has already registered" } } ``` ::: ### 登入 Login :::warning **POST** /api/member/login ::: | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | email(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 會員信箱 | | password(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 會員密碼 | --- :::warning Request ```json= { "email": "peter@gmail.com", //member email "password": "123" //member password } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "status": "Success", "result": "Welcom peter" } ``` Headers ```json= { "token": "[JWT Token]"//登入成功後,分配一個token給使用者 } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Email 或是密碼錯誤 ```json= { "result": { "status": "Login fail", "err": "Please enter correct email and password" } } ``` ::: ### 修改資料 Modify :::info **PUT** /api/member ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | name(<font color = "#FD0000">required</font>) | String | x-www-form-urlencoded | 新會員名稱 | | password(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 新會員密碼 | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ```json= { "name": "peterUpdate", //member name "password": "123123" //member password } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Success", "memberUpdateData": { "name": "peterUpdate", "password": "[Encrypted password]",//加密後的密碼 "update_date": "2021-09-25 18:21:23" } } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ## 商品 Product ### 取得商品 Get Product List :::success **GET** /api/product ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": [ { "id": 1, "name": "camera", "price": 1000, "stock_quantity": 100, "img": null, "img": null, "remark": "Leica M3", "update_date": null, "create_date": "2021-10-11 16:00:00" }, { "id": 2, "name": "lens", "price": 10, "stock_quantity": 20, "img": null, "img": null, "remark": "Leica 28mm", "update_date": null, "create_date": "2021-10-11 16:00:00" }, ...其他產品 ] } ``` ::: ## 訂單 Order ### 取得所有訂單 Get All Orders :::success **GET** /api/order ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": [ { "order_id": 1, "member_id": 1, "product_id": 2, "order_quantity": 10, "order_price": 2000, "is_complete": 0, "update_date": "2021-09-20 13:00:00" }, { "order_id": 1, "member_id": 1, "product_id": 3, "order_quantity": 20, "order_price": 600, "is_complete": 0, "update_date": "2021-09-20 13:00:00" }, ] } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ### 取得單筆訂單 Get member Orders :::success **GET** /api/order/member ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Order created Successfully", "orderData": [ { "order_id": 1, "memberID": 2, "product_id": "1", "order_quantity": 1, "order_price": 1000, "create_date": "2021-09-25 18:49:56", "is_complete": 0 }, { "order_id": 1, "memberID": 2, "product_id": "2", "order_quantity": 2, "order_price": 50, "create_date": "2021-09-25 18:49:56", "is_complete": 0 }, { "order_id": 1, "memberID": 2, "product_id": "3", "order_quantity": 2, "order_price": 400, "create_date": "2021-09-25 18:49:56", "is_complete": 0 } ] } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ### 新增訂單 Create Order :::warning **POST** /api/order ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | productID(<font color = "#FD0000">required</font>) | String | x-www-form-urlencoded | 商品ID | | quantity(<font color = "#FD0000">required</font>)| Int | x-www-form-urlencoded | 商品數量 | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ```json= { "productID": "1, 2, 3", //要訂購的商品ID "quantiy": 1, 2, 1 //依序每種商品的訂購數量 } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Order created Successfully", "orderData": [ { "order_id": 1, "memberID": 2, "product_id": "1", "order_quantity": 1, "order_price": 1000, "create_date": "2021-09-25 18:49:56", "is_complete": 0 }, { "order_id": 1, "memberID": 2, "product_id": "2", "order_quantity": 2, "order_price": 50, "create_date": "2021-09-25 18:49:56", "is_complete": 0 }, { "order_id": 1, "memberID": 2, "product_id": "3", "order_quantity": 2, "order_price": 400, "create_date": "2021-09-25 18:49:56", "is_complete": 0 } ] } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ### 修改訂單 Modify Order :::info **PUT** /api/order ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | orderID(<font color = "#FD0000">required</font>) | String | x-www-form-urlencoded | 訂單編號 | | productID(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 產品編號 | | quantity(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 修改後數量 | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ```json= { "orderID": "6", //訂單編號 "productID": "2", //產品編號 "quantity": "3" //修改後數量 } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Update order successfully", "updateOrderData": { "orderID": "6", //訂單編號 "memberID": 9, "productID": "2", //產品編號 "quantity": "3" //修改後數量 "update_date": "2021-09-25 18:21:23" } } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ### 刪除訂單 Delete Order :::danger **DELETE** /api/order ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | orderID(<font color = "#FD0000">required</font>) | Int | x-www-form-urlencoded | 訂單編號 | | productID(<font color = "#FD0000">required</font>)| String | x-www-form-urlencoded | 產品編號 | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ```json= { "orderID": "6", //訂單編號 "productID": "2", //產品編號 } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Delete the order successfully", "deleteOrderData": { "orderID": "6", //訂單編號 "memberID": 9, "productID": "2", //產品編號 } } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: 找不到訂單 ```json= { "result": { "status": "Delete the order fail", "err": "Can not find the order." } } ``` Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: ### 完成訂單 Complete Order :::info **PUT** /api/order/complete ::: | Headers | Key | Value | 描述 | | --- | ----- | ----------- |----------- | | | token | [JWT Token] | 登入後的token | | Body參數 | 類型 | 傳輸格式 | 描述 | | ---------------------------------------------- | ------ | --------------------- | -------- | | orderID(<font color = "#FD0000">required</font>) | Int | x-www-form-urlencoded | 訂單編號 | --- :::warning Request Header ```json= { "token": "[JWT token]" } ``` ```json= { "orderID": "6", //訂單編號 } ``` ::: <font color = "green">**Success 200**</font> :::success Response ```json= { "result": { "status": "Order id: 6 payment complished. thanks for using our service! Order detail will be send to peter@gmail.com" } } ``` ::: <font color="red">**Error**</font> :::danger Response Error type: Token過期/Token錯誤 ```json= { "result": { "status": "Wrong token", "err": "Please login agin." } } ::: User flows --- Project Timeline --- ## Contact me :::info **GITHub:** https://github.com/ec1348/shopping_cart **Email:** ec1348@gmail.com **Call:** 0970834201 ::: ###### tags: `API` `Shpping Cart` `Member System`