# API Details - Order
###### tags: `API Details`
#### 取得全部訂單列表
Response Example
```json
{
"ok": 1,
"data": [
{
"id": 107,
"orderNumber": "nt2f5fzdhsxd",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": false,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
},
{
"id": 106,
"orderNumber": "e250d5mpo66r",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 10,
"totalPrice": 262,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": true,
"isCanceledByVendor": false,
"isCanceledByClient": true,
"createdAt": "2021-10-03T04:15:31.000Z",
"updatedAt": "2021-10-03T18:25:06.000Z"
}
]
}
```
#### 取得自己買的訂單列表
Response Example
```json
{
"ok": 1,
"data": [
{
"id": 107,
"orderNumber": "nt2f5fzdhsxd",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": false,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
},
{
"id": 106,
"orderNumber": "e250d5mpo66r",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 10,
"totalPrice": 262,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": true,
"isCanceledByVendor": false,
"isCanceledByClient": true,
"createdAt": "2021-10-03T04:15:31.000Z",
"updatedAt": "2021-10-03T18:25:06.000Z"
}
]
}
```
#### 取得自己賣的訂單列表
Response Example
```json
{
"ok": 1,
"data": [
{
"id": 107,
"orderNumber": "nt2f5fzdhsxd",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": false,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
},
{
"id": 106,
"orderNumber": "e250d5mpo66r",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 10,
"totalPrice": 262,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": true,
"isCanceledByVendor": false,
"isCanceledByClient": true,
"createdAt": "2021-10-03T04:15:31.000Z",
"updatedAt": "2021-10-03T18:25:06.000Z"
}
]
}
```
#### 取得單一訂單明細
Response Example
```json
{
"ok": 1,
"data": {
"order": {
"id": 107,
"orderNumber": "nt2f5fzdhsxd",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": false,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
},
"orderItems": [
{
"id": 14,
"productId": 3,
"orderId": 107,
"quantity": 10,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z",
"Product": {
"id": 3,
"vendorId": 1,
"name": "玉米罐頭",
"categoryId": 1,
"pictureUrl": "https://i.imgur.com/mHWygJg.png",
"price": 2,
"quantity": 380,
"manufactureDate": null,
"expiryDate": null,
"description": "123",
"isAvailable": true,
"createdAt": "2021-10-01T11:59:07.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
}
},
{
"id": 15,
"productId": 2,
"orderId": 107,
"quantity": 10,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z",
"Product": {
"id": 2,
"vendorId": 1,
"name": "烤香腸",
"categoryId": 1,
"pictureUrl": "https://i.imgur.com/UqorRbJ.png",
"price": 262,
"quantity": 290,
"manufactureDate": null,
"expiryDate": "1959-12-31T16:00:00.000Z",
"description": "123",
"isAvailable": true,
"createdAt": "2021-10-01T11:58:57.000Z",
"updatedAt": "2021-10-03T18:24:56.000Z"
}
},
{
"id": 16,
"productId": 1,
"orderId": 107,
"quantity": 10,
"createdAt": "2021-10-03T18:10:23.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z",
"Product": {
"id": 1,
"vendorId": 1,
"name": "food",
"categoryId": 1,
"pictureUrl": "https://i.imgur.com/ptpIhC0.png",
"price": 0,
"quantity": 1994,
"manufactureDate": null,
"expiryDate": "1959-12-31T16:00:00.000Z",
"description": "123",
"isAvailable": true,
"createdAt": "2021-09-29T15:35:49.000Z",
"updatedAt": "2021-10-03T18:10:23.000Z"
}
}
]
}
}
```
#### 成立訂單
- 新增一張訂單 orders
- 有訂單之後,把購物車商品新增成這張訂單的訂單商品 order_items
- 同時要把要下單的購物車商品從購物車裡刪掉 cart_items
- `orderProducts` 存在 localStorage,呼叫 API 前需先將 `orderProducts` 取出
- request 為 JSON 格式
Request Example
```json
{
"orderProducts": [
{
"id": 3,
"quantity": 10
},
{
"id": 2,
"quantity": 10
},
{
"id": 1,
"quantity": 10
}
],
"vendorId": 1,
"pickupTime": "2021-10-04T14:17:45.120Z",
"remarks": "謝謝老闆~"
}
```
Response Example
```json
{
"ok": 1,
"data": {
"id": 109,
"orderNumber": "51rg27lhmhcm",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "老闆辛苦了",
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": false,
"updatedAt": "2021-10-04T14:17:45.120Z",
"createdAt": "2021-10-04T14:17:45.085Z"
}
}
```
#### 訂單完成
買家點選「完成付款」,要驗證使用者是否和該訂單的 client_id 一樣
Response Example
```json
{
"ok": 1,
"data": {
"id": 108,
"orderNumber": "resqj87jzlzf",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": "2021-10-04T19:59:57.000Z",
"remarks": "我有帶環保杯~",
"isPaid": false,
"isCompleted": true,
"isCanceledByVendor": false,
"isCanceledByClient": true,
"createdAt": "2021-10-04T13:59:57.000Z",
"updatedAt": "2021-10-04T14:21:16.690Z"
}
}
```
#### 訂單取消
Response Example
```json
{
"ok": 1,
"data": {
"id": 108,
"orderNumber": "resqj87jzlzf",
"vendorId": 1,
"clientId": 2,
"totalQuantity": 30,
"totalPrice": 264,
"pickupTime": null,
"remarks": "我會自備購物袋",
"isPaid": false,
"isCompleted": false,
"isCanceledByVendor": false,
"isCanceledByClient": true,
"createdAt": "2021-10-04T13:59:57.000Z",
"updatedAt": "2021-10-04T14:00:36.908Z"
}
}
```
#### 刪除訂單
Response Example
```json
{
"ok": 1,
"message": "Success"
}
```