add
add the pageInfo, keyword to client list
| | |
| | | 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 == "" { |
| | |
| | | |
| | | 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, ¶ms) |
| | | 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), |
| | | }) |
| | | } |
| | |
| | | } |
| | | }, |
| | | "/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", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetClientList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | | }, |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "response.ClientResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "count": { |
| | | "type": "integer" |
| | | }, |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | } |
| | | }, |
| | | "/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", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.GetClientList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | | }, |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.GetContactList": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "response.ClientResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "count": { |
| | | "type": "integer" |
| | | }, |
| | | "list": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | 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: |
| | |
| | | type: object |
| | | response.ClientResponse: |
| | | properties: |
| | | count: |
| | | type: integer |
| | | list: |
| | | items: |
| | | $ref: '#/definitions/model.Client' |
| | |
| | | tags: |
| | | - Client |
| | | /api/client/list: |
| | | get: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.GetClientList' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | data: |
| | | $ref: '#/definitions/response.ClientResponse' |
| | | type: object |
| | | summary: 获取客户列表 |
| | | summary: 客户列表 |
| | | tags: |
| | | - Client |
| | | /api/client/update: |
| | |
| | | |
| | | ClientSearch struct { |
| | | Client |
| | | Orm *gorm.DB |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | 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) |
| | | } |
| | |
| | | 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 |
| | | } |
| | |
| | | Id int `json:"id"` |
| | | Client |
| | | } |
| | | |
| | | type GetClientList struct { |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | } |
| | |
| | | } |
| | | |
| | | ClientResponse struct { |
| | | List []*model.Client `json:"list"` |
| | | List []*model.Client `json:"list"` |
| | | Count int `json:"count"` |
| | | } |
| | | |
| | | ClientStatusResponse struct { |
| | |
| | | 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) // 获取客户列表 |
| | | } |
| | | } |
| | | } |
| | |
| | | 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() |
| | |
| | | |
| | | 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 |
| | | } |