fix
wangpengfei
2023-08-02 46f410ae18f22f5e9a8368f0ea7c721863d18fce
fix

add batch delete function to contact module
8个文件已修改
110 ■■■■■ 已修改文件
api/v1/contact.go 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/contact.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/contact.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/contact.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contact.go
@@ -7,7 +7,6 @@
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "github.com/gin-gonic/gin"
    "strconv"
)
type ContactApi struct{}
@@ -47,17 +46,17 @@
//    @Tags        Contact
//    @Summary    删除联系人
//    @Produce    application/json
//    @Param        id    path        int    true    "查询参数"
//    @Param        object    body        request.DeleteContact true    "查询参数"
//    @Success    200    {object}    contextx.Response{}
//    @Router        /api/contact/delete/{id} [delete]
//    @Router        /api/contact/delete [delete]
func (con *ContactApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    var params request.DeleteContact
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := contactService.DeleteContact(id)
    errCode := contactService.DeleteContact(params.Ids)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
@@ -170,4 +169,4 @@
        List:  contacts,
        Count: int(total),
    })
}
}
docs/docs.go
@@ -1109,7 +1109,7 @@
                }
            }
        },
        "/api/contact/delete/{id}": {
        "/api/contact/delete": {
            "delete": {
                "produces": [
                    "application/json"
@@ -1120,11 +1120,13 @@
                "summary": "删除联系人",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.DeleteContact"
                        }
                    }
                ],
                "responses": {
@@ -9932,6 +9934,17 @@
                }
            }
        },
        "request.DeleteContact": {
            "type": "object",
            "properties": {
                "ids": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            }
        },
        "request.DeleteCountry": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -1097,7 +1097,7 @@
                }
            }
        },
        "/api/contact/delete/{id}": {
        "/api/contact/delete": {
            "delete": {
                "produces": [
                    "application/json"
@@ -1108,11 +1108,13 @@
                "summary": "删除联系人",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.DeleteContact"
                        }
                    }
                ],
                "responses": {
@@ -9920,6 +9922,17 @@
                }
            }
        },
        "request.DeleteContact": {
            "type": "object",
            "properties": {
                "ids": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            }
        },
        "request.DeleteCountry": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -1905,6 +1905,13 @@
          type: integer
        type: array
    type: object
  request.DeleteContact:
    properties:
      ids:
        items:
          type: integer
        type: array
    type: object
  request.DeleteCountry:
    properties:
      id:
@@ -4753,14 +4760,15 @@
      summary: 添加联系人
      tags:
      - Contact
  /api/contact/delete/{id}:
  /api/contact/delete:
    delete:
      parameters:
      - description: 查询参数
        in: path
        name: id
        in: body
        name: object
        required: true
        type: integer
        schema:
          $ref: '#/definitions/request.DeleteContact'
      produces:
      - application/json
      responses:
model/contact.go
@@ -168,4 +168,8 @@
func (slf *ContactSearch) SetOrder(order string) *ContactSearch {
    slf.OrderBy = order
    return slf
}
}
func (slf *ContactSearch) SetIds(ids []int) *ContactSearch {
    slf.Orm = slf.Orm.Where("id in (?)", ids)
    return slf
}
model/request/contact.go
@@ -31,3 +31,7 @@
    PageInfo
    Keyword string `json:"keyword"`
}
type DeleteContact struct {
    Ids []int `json:"ids"`
}
router/contact.go
@@ -12,7 +12,7 @@
    contactApi := v1.ApiGroup.ContactApi
    {
        contactRouter.POST("add", contactApi.Add)             // 添加联系人
        contactRouter.DELETE("delete/:id", contactApi.Delete) // 删除联系人
        contactRouter.DELETE("delete", contactApi.Delete)     // 删除联系人
        contactRouter.PUT("update", contactApi.Update)        // 更新联系人
        contactRouter.POST("list", contactApi.List)            // 获取联系人列表
    }
service/contact.go
@@ -33,20 +33,6 @@
    return ecode.OK
}
func (ContactService) DeleteContact(id int) int {
    // check contact exist
    _, err := model.NewContactSearch(nil).SetId(id).First()
    if err != nil {
        return ecode.ContactNotExist
    }
    // delete contact
    err = model.NewContactSearch(nil).SetId(id).Delete()
    if err != nil {
        return ecode.ContactDeleteErr
    }
    return ecode.OK
}
func (ContactService) UpdateContact(contact *model.Contact) int {
    // check contact exist
@@ -125,3 +111,12 @@
    }
    return contacts, total, ecode.OK
}
func (ContactService) DeleteContact (ids []int) int {
    // delete client
    err := model.NewContactSearch(nil).SetIds(ids).Delete()
    if err != nil {
        return ecode.ContactDeleteErr
    }
    return ecode.OK
}