From 46f410ae18f22f5e9a8368f0ea7c721863d18fce Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期三, 02 八月 2023 17:22:35 +0800
Subject: [PATCH] fix

---
 service/contact.go       |   23 ++++-------
 router/contact.go        |    2 
 api/v1/contact.go        |   13 +++---
 docs/swagger.yaml        |   16 ++++++--
 model/contact.go         |    6 ++
 docs/docs.go             |   23 +++++++++--
 docs/swagger.json        |   23 +++++++++--
 model/request/contact.go |    4 ++
 8 files changed, 73 insertions(+), 37 deletions(-)

diff --git a/api/v1/contact.go b/api/v1/contact.go
index 2fd3dd4..9d68a2d 100644
--- a/api/v1/contact.go
+++ b/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),
 	})
-}
\ No newline at end of file
+}
diff --git a/docs/docs.go b/docs/docs.go
index 20ef8a0..109093a 100644
--- a/docs/docs.go
+++ b/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": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 76b7c6e..55b7c9e 100644
--- a/docs/swagger.json
+++ b/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": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 5283f1d..ddfa118 100644
--- a/docs/swagger.yaml
+++ b/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:
diff --git a/model/contact.go b/model/contact.go
index 3fc6048..abadcea 100644
--- a/model/contact.go
+++ b/model/contact.go
@@ -168,4 +168,8 @@
 func (slf *ContactSearch) SetOrder(order string) *ContactSearch {
 	slf.OrderBy = order
 	return slf
-}
\ No newline at end of file
+}
+func (slf *ContactSearch) SetIds(ids []int) *ContactSearch {
+	slf.Orm = slf.Orm.Where("id in (?)", ids)
+	return slf
+}
diff --git a/model/request/contact.go b/model/request/contact.go
index 1c39699..3156038 100644
--- a/model/request/contact.go
+++ b/model/request/contact.go
@@ -31,3 +31,7 @@
 	PageInfo
 	Keyword string `json:"keyword"`
 }
+
+type DeleteContact struct {
+	Ids []int `json:"ids"`
+}
diff --git a/router/contact.go b/router/contact.go
index dcca60c..9e1b821 100644
--- a/router/contact.go
+++ b/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)            // 鑾峰彇鑱旂郴浜哄垪琛�
 	}
diff --git a/service/contact.go b/service/contact.go
index 8a3e761..7b61053 100644
--- a/service/contact.go
+++ b/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
+}
\ No newline at end of file

--
Gitblit v1.8.0