fix
add batch delete function to contact module
| | |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ContactApi struct{} |
| | |
| | | // @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, ¶ms) |
| | | 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 |
| | |
| | | List: contacts, |
| | | Count: int(total), |
| | | }) |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/contact/delete/{id}": { |
| | | "/api/contact/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "summary": "删除联系人", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteContact" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteContact": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteCountry": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/contact/delete/{id}": { |
| | | "/api/contact/delete": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | |
| | | "summary": "删除联系人", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.DeleteContact" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteContact": { |
| | | "type": "object", |
| | | "properties": { |
| | | "ids": { |
| | | "type": "array", |
| | | "items": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.DeleteCountry": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DeleteContact: |
| | | properties: |
| | | ids: |
| | | items: |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.DeleteCountry: |
| | | properties: |
| | | id: |
| | |
| | | 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: |
| | |
| | | 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 |
| | | } |
| | |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | } |
| | | |
| | | type DeleteContact struct { |
| | | Ids []int `json:"ids"` |
| | | } |
| | |
| | | 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) // 获取联系人列表 |
| | | } |
| | |
| | | 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 |
| | |
| | | } |
| | | 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 |
| | | } |