fix
Add Batch Add Functionality for Products
| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body test.Product true "创建Product" |
| | | // @Param data body request.ProductCreate true "创建Product" |
| | | // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" |
| | | // @Router /p/createProduct [post] |
| | | func (pApi *ProductApi) CreateProduct(c *gin.Context) { |
| | | var p test.Product |
| | | var p testReq.ProductCreate |
| | | err := c.ShouldBindJSON(&p) |
| | | if err != nil { |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | if err := pService.CreateProduct(&p); err != nil { |
| | | if err := pService.CreateProduct(p.List); err != nil { |
| | | global.GVA_LOG.Error("创建失败!", zap.Error(err)) |
| | | response.FailWithMessage("创建失败", c) |
| | | } else { |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.ProductCreate" |
| | | } |
| | | } |
| | | ], |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.ProductCreate": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Product" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.Register": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Product" |
| | | "$ref": "#/definitions/request.ProductCreate" |
| | | } |
| | | } |
| | | ], |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.ProductCreate": { |
| | | "type": "object", |
| | | "properties": { |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Product" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.Register": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | description: 每页大小 |
| | | type: integer |
| | | type: object |
| | | request.ProductCreate: |
| | | properties: |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/test.Product' |
| | | type: array |
| | | type: object |
| | | request.Register: |
| | | properties: |
| | | authorityId: |
| | |
| | | name: data |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/test.Product' |
| | | $ref: '#/definitions/request.ProductCreate' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` |
| | | request.PageInfo |
| | | } |
| | | |
| | | type ProductCreate struct { |
| | | List []*test.Product `json:"list"` |
| | | } |
| | |
| | | |
| | | // CreateProduct 创建Product记录 |
| | | // Author [piexlmax](https://github.com/piexlmax) |
| | | func (pService *ProductService) CreateProduct(p *test.Product) (err error) { |
| | | func (pService *ProductService) CreateProduct(p []*test.Product) (err error) { |
| | | err = global.GVA_DB.Create(p).Error |
| | | return err |
| | | } |