From da23babe80de0d32e736e8777430ddfbf185373a Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期二, 25 七月 2023 19:28:11 +0800
Subject: [PATCH] fix

---
 service/contact.go         |   17 ++--
 api/v1/salesLeads.go       |    2 
 model/contacts.go          |   25 ++++++
 router/contact.go          |    4 
 api/v1/contact.go          |   51 ++++++------
 docs/swagger.yaml          |   24 +++++
 docs/docs.go               |   34 ++++++++
 docs/swagger.json          |   34 ++++++++
 model/response/response.go |    6 
 model/request/contact.go   |    5 +
 10 files changed, 157 insertions(+), 45 deletions(-)

diff --git a/api/v1/contact.go b/api/v1/contact.go
index 001ecc9..136b7ab 100644
--- a/api/v1/contact.go
+++ b/api/v1/contact.go
@@ -66,30 +66,6 @@
 	ctx.Ok()
 }
 
-// List
-//
-//	@Tags		Contact
-//	@Summary	鑱旂郴浜哄垪琛�
-//	@Produce	application/json
-//	@Success	200	{object}	contextx.Response{data=response.ContactResponse}
-//	@Router		/api/contact/list [get]
-func (con *ContactApi) List(c *gin.Context) {
-	ctx, ok := contextx.NewContext(c, nil)
-	if !ok {
-		return
-	}
-
-	contacts, errCode := contactService.GetContactList()
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.OkWithDetailed(response.ContactResponse{
-		List: contacts,
-	})
-}
-
 // Update
 //
 //	@Tags		Contact
@@ -168,3 +144,30 @@
 	contact.IsFirst = params.IsFirst
 	return ecode.OK, contact
 }
+
+// List
+//
+//	@Tags		Contact
+//	@Summary	鑱旂郴浜哄垪琛�
+//	@Produce	application/json
+//	@Param		object	body		request.GetContactList	true	"鍙傛暟"
+//	@Success	200		{object}	contextx.Response{data=response.ContactResponse}
+//	@Router		/api/contact/list [post]
+func (con *ContactApi) List(c *gin.Context) {
+	var params request.GetContactList
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	contacts, errCode := contactService.GetContactList(params.Page, params.PageSize, params.Keyword)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.ContactResponse{
+		List:  contacts,
+		Count: len(contacts),
+	})
+}
diff --git a/api/v1/salesLeads.go b/api/v1/salesLeads.go
index 137b398..a71d127 100644
--- a/api/v1/salesLeads.go
+++ b/api/v1/salesLeads.go
@@ -105,7 +105,7 @@
 //	@Summary	鑾峰彇閿�鍞嚎绱㈠垪琛�
 //	@Produce	application/json
 //	@Success	200	{object}	contextx.Response{data=response.SalesLeadsResponse}
-//	@Router		/api/salesLeads/list [get]
+//	@Router		/api/salesLeads/list [post]
 func (s *SalesLeadsApi) List(c *gin.Context) {
 	ctx, ok := contextx.NewContext(c, nil)
 	if !ok {
diff --git a/docs/docs.go b/docs/docs.go
index 4fa51ec..ec37d32 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -1095,7 +1095,7 @@
             }
         },
         "/api/contact/list": {
-            "get": {
+            "post": {
                 "produces": [
                     "application/json"
                 ],
@@ -1103,6 +1103,17 @@
                     "Contact"
                 ],
                 "summary": "鑱旂郴浜哄垪琛�",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetContactList"
+                        }
+                    }
+                ],
                 "responses": {
                     "200": {
                         "description": "OK",
@@ -4816,7 +4827,7 @@
             }
         },
         "/api/salesLeads/list": {
-            "get": {
+            "post": {
                 "produces": [
                     "application/json"
                 ],
@@ -9703,6 +9714,22 @@
                 }
             }
         },
+        "request.GetContactList": {
+            "type": "object",
+            "properties": {
+                "keyword": {
+                    "type": "string"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                }
+            }
+        },
         "request.GetUserList": {
             "type": "object",
             "properties": {
@@ -11813,6 +11840,9 @@
         "response.ContactResponse": {
             "type": "object",
             "properties": {
+                "count": {
+                    "type": "integer"
+                },
                 "list": {
                     "type": "array",
                     "items": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 5a0d9e4..90fdfc8 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1083,7 +1083,7 @@
             }
         },
         "/api/contact/list": {
-            "get": {
+            "post": {
                 "produces": [
                     "application/json"
                 ],
@@ -1091,6 +1091,17 @@
                     "Contact"
                 ],
                 "summary": "鑱旂郴浜哄垪琛�",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.GetContactList"
+                        }
+                    }
+                ],
                 "responses": {
                     "200": {
                         "description": "OK",
@@ -4804,7 +4815,7 @@
             }
         },
         "/api/salesLeads/list": {
-            "get": {
+            "post": {
                 "produces": [
                     "application/json"
                 ],
@@ -9691,6 +9702,22 @@
                 }
             }
         },
+        "request.GetContactList": {
+            "type": "object",
+            "properties": {
+                "keyword": {
+                    "type": "string"
+                },
+                "page": {
+                    "description": "椤电爜",
+                    "type": "integer"
+                },
+                "pageSize": {
+                    "description": "姣忛〉澶у皬",
+                    "type": "integer"
+                }
+            }
+        },
         "request.GetUserList": {
             "type": "object",
             "properties": {
@@ -11801,6 +11828,9 @@
         "response.ContactResponse": {
             "type": "object",
             "properties": {
+                "count": {
+                    "type": "integer"
+                },
                 "list": {
                     "type": "array",
                     "items": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index ef0759e..eb954b6 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1907,6 +1907,17 @@
       topic:
         type: string
     type: object
+  request.GetContactList:
+    properties:
+      keyword:
+        type: string
+      page:
+        description: 椤电爜
+        type: integer
+      pageSize:
+        description: 姣忛〉澶у皬
+        type: integer
+    type: object
   request.GetUserList:
     properties:
       keyword:
@@ -3318,6 +3329,8 @@
     type: object
   response.ContactResponse:
     properties:
+      count:
+        type: integer
       list:
         items:
           $ref: '#/definitions/model.ContactDetail'
@@ -4475,7 +4488,14 @@
       tags:
       - Contact
   /api/contact/list:
-    get:
+    post:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.GetContactList'
       produces:
       - application/json
       responses:
@@ -6760,7 +6780,7 @@
       tags:
       - SalesLeads
   /api/salesLeads/list:
-    get:
+    post:
       produces:
       - application/json
       responses:
diff --git a/model/contacts.go b/model/contacts.go
index 98d7805..7e7b9bb 100644
--- a/model/contacts.go
+++ b/model/contacts.go
@@ -26,7 +26,12 @@
 
 	ContactSearch struct {
 		Contact
-		Orm *gorm.DB
+
+		Orm      *gorm.DB
+		Keyword  string
+		OrderBy  string
+		PageNum  int
+		PageSize int
 	}
 
 	ContactDetail struct {
@@ -51,6 +56,9 @@
 
 func (slf *ContactSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Contact{})
+	if slf.Keyword != "" {
+		db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
+	}
 	if slf.Id != 0 {
 		db = db.Where("id = ?", slf.Id)
 	}
@@ -137,3 +145,18 @@
 	var db = slf.build()
 	return db.Updates(data).Error
 }
+
+func (slf *ContactSearch) SetKeyword(keyword string) *ContactSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
+func (slf *ContactSearch) SetPage(page, size int) *ContactSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ContactSearch) SetOrder(order string) *ContactSearch {
+	slf.OrderBy = order
+	return slf
+}
diff --git a/model/request/contact.go b/model/request/contact.go
index 5b16b31..1c39699 100644
--- a/model/request/contact.go
+++ b/model/request/contact.go
@@ -26,3 +26,8 @@
 	Id int `json:"id"`
 	Contact
 }
+
+type GetContactList struct {
+	PageInfo
+	Keyword string `json:"keyword"`
+}
diff --git a/model/response/response.go b/model/response/response.go
index 04ea37d..895fe96 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -47,7 +47,8 @@
 	}
 
 	ContactResponse struct {
-		List []*model.ContactDetail `json:"list"`
+		List  []*model.ContactDetail `json:"list"`
+		Count int                    `json:"count"`
 	}
 
 	ClientResponse struct {
@@ -182,7 +183,6 @@
 
 		// 甯佺
 		Currency []*model.Currency `json:"currency"`
-
 
 		// 鎶ヤ环鍗曠姸鎬�
 		QuotationStatus []*model.QuotationStatus `json:"quotationStatus"`
@@ -328,4 +328,4 @@
 	CurrencyResponse struct {
 		List []*model.Currency `json:"list"`
 	}
-)
\ No newline at end of file
+)
diff --git a/router/contact.go b/router/contact.go
index 89cb965..dcca60c 100644
--- a/router/contact.go
+++ b/router/contact.go
@@ -14,6 +14,6 @@
 		contactRouter.POST("add", contactApi.Add)             // 娣诲姞鑱旂郴浜�
 		contactRouter.DELETE("delete/:id", contactApi.Delete) // 鍒犻櫎鑱旂郴浜�
 		contactRouter.PUT("update", contactApi.Update)        // 鏇存柊鑱旂郴浜�
-		contactRouter.GET("list", contactApi.List)            // 鑾峰彇鑱旂郴浜哄垪琛�
+		contactRouter.POST("list", contactApi.List)            // 鑾峰彇鑱旂郴浜哄垪琛�
 	}
-}
+}
\ No newline at end of file
diff --git a/service/contact.go b/service/contact.go
index c62bc8a..8333495 100644
--- a/service/contact.go
+++ b/service/contact.go
@@ -48,14 +48,6 @@
 	return ecode.OK
 }
 
-func (ContactService) GetContactList() ([]*model.ContactDetail, int) {
-	// get contact list
-	contacts, err := model.NewContactSearch(nil).FindAll()
-	if err != nil {
-		return nil, ecode.ContactListErr
-	}
-	return contacts, ecode.OK
-}
 
 func (ContactService) UpdateContact(contact *model.Contact) int {
 	// check contact exist
@@ -125,3 +117,12 @@
 
 	return ecode.OK
 }
+
+func (ContactService) GetContactList(page, pageSize int, keyword string) ([]*model.ContactDetail, int) {
+	// get contact list
+	contacts, err := model.NewContactSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).FindAll()
+	if err != nil {
+		return nil, ecode.ContactListErr
+	}
+	return contacts, ecode.OK
+}

--
Gitblit v1.8.0