quantum_stack_interview/docs/api/shop.md

205 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# shop
Base URLs: http://127.0.0.1:8000/shop/
## GET 搜索商品
GET /shop/product/search/
支持关键词搜索,包含名字、编号、描述、关键词(或者应该叫标签)
### 请求参数
|名称|位置|类型|必选|说明|
|---|---|---|---|---|
|q|query|string| 是 |关键词|
|page|query|integer| 否 |页码|
|page_size|query|integer| 否 |页面大小最大100|
> 返回示例
> 200 Response
```json
{
"products": [
{
"id": 10,
"name": "e",
"description": "效关科造区最飞阶。就见除据区眼求该合。今新料。",
"price": "19.20",
"stock": 7387915975153562,
"keywords": "天也商"
},
{
"id": 11,
"name": "e",
"description": "效关科造区最飞阶。就见除据区眼求该合。今新料。",
"price": "123.20",
"stock": 7387915975153562,
"keywords": "天也商"
}
]
}
```
### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
### 返回数据结构
状态码 **200**
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» products|[object]|true|none||none|
|»» id|integer|true|none||none|
|»» name|string|true|none|商品名称|none|
|»» description|string|true|none|商品描述|none|
|»» price|string|true|none|商品价格 |none|
|»» stock|integer|true|none|商品库存|none|
|»» keywords|string|true|none|商品关键词|none|
## POST 批量下单接口
POST /shop/order/batch/
批量下单商品
> Body 请求参数
```json
{
"items": [
{
"product_id": 0,
"quantity": 0
}
]
}
```
### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|body|body|object| 否 ||none|
|» items|body|[object]| 是 ||none|
|»» product_id|body|integer| 是 | 下单商品id|none|
|»» quantity|body|integer| 是 | 下单数量|none|
> 返回示例
> 200 Response
```json
{
"order_id": 13,
"results": [
{
"product_id": 1,
"status": "success"
},
{
"product_id": 5,
"status": "success"
},
{
"product_id": 86,
"status": "failed",
"reason": "商品不存在"
}
]
}
```
### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
### 返回数据结构
状态码 **200**
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» order_id|integer|true|none||none|
|» results|[object]|true|none||none|
|»» product_id|integer|true|none|下单商品id|none|
|»» status|string|true|none|下单结果|none|
|»» reason|string|false|none|错误信息|none|
## POST 新增商品
POST /shop/product/create/
新增商品
> Body 请求参数
```json
{
"data": {
"name": "string",
"price": 0,
"stock": 0,
"description": "string",
"keywords": "string"
}
}
```
### 请求参数
|名称|位置|类型|必选|中文名|说明|
|---|---|---|---|---|---|
|body|body|object| 否 ||none|
|» data|body|object| 是 ||none|
|»» name|body|string| 是 | 商品名称|none|
|»» price|body|integer| 是 | 商品价格|none|
|»» stock|body|integer| 是 | 商品库存|none|
|»» description|body|string| 否 | 商品描述|none|
|»» keywords|body|string| 否 | 商品关键词|none|
> 返回示例
> 200 Response
```json
{
"result": {
"id": 14,
"name": "x",
"description": "者车重转必维目马。作属时看区低验什声。无使山精出如。",
"price": "943941625",
"stock": 5203132084980572,
"keywords": "收适面"
}
}
```
### 返回结果
|状态码|状态码含义|说明|数据模型|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
### 返回数据结构
状态码 **200**
|名称|类型|必选|约束|中文名|说明|
|---|---|---|---|---|---|
|» result|object|true|none||none|
|»» id|integer|true|none||none|
|»» name|string|true|none|商品名称|none|
|»» description|string|true|none|商品描述|none|
|»» price|string|true|none|商品价格|none|
|»» stock|integer|true|none|商品库存|none|
|»» keywords|string|true|none|商品关键词|none|