add
wangpengfei
2023-07-25 163257e81abbf954ba140ce22098fa78a66aa682
add

add the pageInfo, keyword to client list
9个文件已修改
198 ■■■■ 已修改文件
api/v1/client.go 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/client.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/client.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/client.go
@@ -44,28 +44,6 @@
    ctx.Ok()
}
// List
//
//    @Tags        Client
//    @Summary    获取客户列表
//    @Produce    application/json
//    @Success    200    {object}    contextx.Response{data=response.ClientResponse}
//    @Router        /api/client/list [get]
func (cli *ClientApi) List(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    errCode, clients := clientService.GetClientList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.ClientResponse{List: clients})
}
func checkClientParams(params request.Client) (int, *model.Client) {
    client := new(model.Client)
    //if params.Name == "" {
@@ -198,3 +176,30 @@
    ctx.Ok()
}
// List
//
//    @Tags        Client
//    @Summary    客户列表
//    @Produce    application/json
//    @Param        object    body        request.GetClientList    true    "参数"
//    @Success    200        {object}    contextx.Response{data=response.ClientResponse}
//    @Router        /api/client/list [post]
func (cli *ClientApi) List(c *gin.Context) {
    var params request.GetClientList
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    clients, errCode := clientService.GetClientList(params.Page, params.PageSize, params.Keyword)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.ClientResponse{
        List:  clients,
        Count: len(clients),
    })
}
docs/docs.go
@@ -500,14 +500,25 @@
            }
        },
        "/api/client/list": {
            "get": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Client"
                ],
                "summary": "获取客户列表",
                "summary": "客户列表",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetClientList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
@@ -9725,6 +9736,22 @@
                }
            }
        },
        "request.GetClientList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
                },
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                }
            }
        },
        "request.GetContactList": {
            "type": "object",
            "properties": {
@@ -11834,6 +11861,9 @@
        "response.ClientResponse": {
            "type": "object",
            "properties": {
                "count": {
                    "type": "integer"
                },
                "list": {
                    "type": "array",
                    "items": {
docs/swagger.json
@@ -488,14 +488,25 @@
            }
        },
        "/api/client/list": {
            "get": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Client"
                ],
                "summary": "获取客户列表",
                "summary": "客户列表",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetClientList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
@@ -9713,6 +9724,22 @@
                }
            }
        },
        "request.GetClientList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
                },
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                }
            }
        },
        "request.GetContactList": {
            "type": "object",
            "properties": {
@@ -11822,6 +11849,9 @@
        "response.ClientResponse": {
            "type": "object",
            "properties": {
                "count": {
                    "type": "integer"
                },
                "list": {
                    "type": "array",
                    "items": {
docs/swagger.yaml
@@ -1907,6 +1907,17 @@
      topic:
        type: string
    type: object
  request.GetClientList:
    properties:
      keyword:
        type: string
      page:
        description: 页码
        type: integer
      pageSize:
        description: 每页大小
        type: integer
    type: object
  request.GetContactList:
    properties:
      keyword:
@@ -3319,6 +3330,8 @@
    type: object
  response.ClientResponse:
    properties:
      count:
        type: integer
      list:
        items:
          $ref: '#/definitions/model.Client'
@@ -4136,7 +4149,14 @@
      tags:
      - Client
  /api/client/list:
    get:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.GetClientList'
      produces:
      - application/json
      responses:
@@ -4149,7 +4169,7 @@
                data:
                  $ref: '#/definitions/response.ClientResponse'
              type: object
      summary: 获取客户列表
      summary: 客户列表
      tags:
      - Client
  /api/client/update:
model/client.go
@@ -34,7 +34,13 @@
    ClientSearch struct {
        Client
        Orm *gorm.DB
                Orm      *gorm.DB
        Keyword  string
        OrderBy  string
        PageNum  int
        PageSize int
    }
)
@@ -54,6 +60,9 @@
func (slf *ClientSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Client{})
    if slf.Keyword != "" {
        db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
    }
    if slf.Id != 0 {
        db.Where("id = ?", slf.Id)
    }
@@ -112,3 +121,18 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *ClientSearch) SetKeyword(keyword string) *ClientSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ClientSearch) SetPage(page, size int) *ClientSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *ClientSearch) SetOrder(order string) *ClientSearch {
    slf.OrderBy = order
    return slf
}
model/request/client.go
@@ -26,3 +26,8 @@
    Id int `json:"id"`
    Client
}
type GetClientList struct {
    PageInfo
    Keyword string `json:"keyword"`
}
model/response/response.go
@@ -52,7 +52,8 @@
    }
    ClientResponse struct {
        List []*model.Client `json:"list"`
        List  []*model.Client `json:"list"`
        Count int             `json:"count"`
    }
    ClientStatusResponse struct {
router/client.go
@@ -14,6 +14,6 @@
        clientRouter.POST("add", clientApi.Add)             // 添加客户
        clientRouter.DELETE("delete/:id", clientApi.Delete) // 删除客户
        clientRouter.PUT("update", clientApi.Update)        // 更新客户
        clientRouter.GET("list", clientApi.List)            // 获取客户列表
        clientRouter.POST("list", clientApi.List)            // 获取客户列表
    }
}
}
service/client.go
@@ -30,16 +30,6 @@
    return ecode.OK
}
func (ClientService) GetClientList() (int, []*model.Client) {
    // get client list
    clients, err := model.NewClientSearch(nil).Find()
    if err != nil {
        return ecode.ClientListErr, nil
    }
    return ecode.OK, clients
}
// CheckClientExist check client exist
func CheckClientExist(id int) int {
    _, err := model.NewClientSearch(nil).SetId(id).First()
@@ -65,3 +55,12 @@
    return ecode.OK
}
func (ClientService) GetClientList(page, pageSize int, keyword string) ([]*model.Client, int) {
    // get contact list
    contacts, err := model.NewClientSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).Find()
    if err != nil {
        return nil, ecode.ClientListErr
    }
    return contacts, ecode.OK
}