fix
wangpengfei
2023-08-28 aa3bc269e46d82bdd6d088e5d07babd2d3b493a1
fix

Add Batch Add Functionality for Products
6个文件已修改
47 ■■■■ 已修改文件
api/v1/test/product.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/request/product.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test/product.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/test/product.go
@@ -26,17 +26,17 @@
// @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 {
docs/docs.go
@@ -3982,7 +3982,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/test.Product"
                            "$ref": "#/definitions/request.ProductCreate"
                        }
                    }
                ],
@@ -7991,6 +7991,17 @@
                }
            }
        },
        "request.ProductCreate": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/test.Product"
                    }
                }
            }
        },
        "request.Register": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -3973,7 +3973,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/test.Product"
                            "$ref": "#/definitions/request.ProductCreate"
                        }
                    }
                ],
@@ -7982,6 +7982,17 @@
                }
            }
        },
        "request.ProductCreate": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/test.Product"
                    }
                }
            }
        },
        "request.Register": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -784,6 +784,13 @@
        description: 每页大小
        type: integer
    type: object
  request.ProductCreate:
    properties:
      list:
        items:
          $ref: '#/definitions/test.Product'
        type: array
    type: object
  request.Register:
    properties:
      authorityId:
@@ -3894,7 +3901,7 @@
        name: data
        required: true
        schema:
          $ref: '#/definitions/test.Product'
          $ref: '#/definitions/request.ProductCreate'
      produces:
      - application/json
      responses:
model/test/request/product.go
@@ -12,3 +12,7 @@
    EndCreatedAt   *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
    request.PageInfo
}
type ProductCreate struct {
    List []*test.Product `json:"list"`
}
service/test/product.go
@@ -12,7 +12,7 @@
// 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
}