From 114b298c2af545e7b63ed5888142dabf5fa62e06 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期一, 17 七月 2023 18:28:23 +0800 Subject: [PATCH] fix --- model/city.go | 8 ++ service/city.go | 19 +++- router/index.go | 3 docs/swagger.yaml | 34 ++++++++ api/v1/city.go | 20 +++- docs/docs.go | 50 ++++++++++++ docs/swagger.json | 50 ++++++++++++ 7 files changed, 170 insertions(+), 14 deletions(-) diff --git a/api/v1/city.go b/api/v1/city.go index 3c37915..724b032 100644 --- a/api/v1/city.go +++ b/api/v1/city.go @@ -13,6 +13,7 @@ type CityApi struct{} // Add +// // @Tags City // @Summary 娣诲姞鍩庡競 // @Produce application/json @@ -44,6 +45,7 @@ } // Set +// // @Tags City // @Summary 璁剧疆鍩庡競 // @Produce application/json @@ -67,18 +69,22 @@ } // List -// @Tags City -// @Summary 鑾峰彇鍩庡競鍒楄〃 -// @Produce application/json -// @Success 200 {object} contextx.Response{data=response.CityResponse} "鎴愬姛" -// @Router /api/city/list [get] +// +// @Tags City +// @Summary 鑾峰彇鍩庡競鍒楄〃 +// @Produce application/json +// @Param provinceId query int false "鐪佷唤ID" +// @Success 200 {object} contextx.Response{data=response.CityResponse} "鎴愬姛" +// @Router /api/city/list [get] func (ci *CityApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } - cities, errCode := cityService.ListCities() + // 鑾峰彇鐪佷唤ID + provinceId, _ := strconv.Atoi(c.Query("provinceId")) + cities, errCode := cityService.ListCities(provinceId) if errCode != ecode.OK { ctx.Fail(errCode) return @@ -90,6 +96,7 @@ } // Delete +// // @Tags City // @Summary 鍒犻櫎鍩庡競 // @Produce application/json @@ -113,6 +120,7 @@ } // Update +// // @Tags City // @Summary 鏇存柊鍩庡競 // @Produce application/json diff --git a/docs/docs.go b/docs/docs.go index ac27a6c..55e80a2 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -232,6 +232,14 @@ "City" ], "summary": "鑾峰彇鍩庡競鍒楄〃", + "parameters": [ + { + "type": "integer", + "description": "鐪佷唤ID", + "name": "provinceId", + "in": "query" + } + ], "responses": { "200": { "description": "鎴愬姛", @@ -4889,6 +4897,29 @@ } } }, + "model.Authority": { + "type": "object", + "properties": { + "authorityName": { + "description": "瑙掕壊鍚�", + "type": "string" + }, + "defaultRouter": { + "description": "榛樿鑿滃崟(榛樿dashboard)", + "type": "string" + }, + "id": { + "description": "瑙掕壊ID", + "type": "integer" + }, + "menus": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Menu" + } + } + } + }, "model.City": { "type": "object", "properties": { @@ -4918,14 +4949,26 @@ "city_id": { "type": "integer" }, + "client_level": { + "$ref": "#/definitions/model.ClientLevel" + }, "client_level_id": { "type": "integer" + }, + "client_origin": { + "$ref": "#/definitions/model.ClientOrigin" }, "client_origin_id": { "type": "integer" }, + "client_status": { + "$ref": "#/definitions/model.ClientStatus" + }, "client_status_id": { "type": "integer" + }, + "client_type": { + "$ref": "#/definitions/model.ClientType" }, "client_type_id": { "type": "integer" @@ -6063,6 +6106,13 @@ "model.User": { "type": "object", "properties": { + "authority": { + "$ref": "#/definitions/model.Authority" + }, + "authorityId": { + "description": "鐢ㄦ埛瑙掕壊ID", + "type": "integer" + }, "companyName": { "type": "string" }, diff --git a/docs/swagger.json b/docs/swagger.json index 68f17b6..27a60ff 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -220,6 +220,14 @@ "City" ], "summary": "鑾峰彇鍩庡競鍒楄〃", + "parameters": [ + { + "type": "integer", + "description": "鐪佷唤ID", + "name": "provinceId", + "in": "query" + } + ], "responses": { "200": { "description": "鎴愬姛", @@ -4877,6 +4885,29 @@ } } }, + "model.Authority": { + "type": "object", + "properties": { + "authorityName": { + "description": "瑙掕壊鍚�", + "type": "string" + }, + "defaultRouter": { + "description": "榛樿鑿滃崟(榛樿dashboard)", + "type": "string" + }, + "id": { + "description": "瑙掕壊ID", + "type": "integer" + }, + "menus": { + "type": "array", + "items": { + "$ref": "#/definitions/model.Menu" + } + } + } + }, "model.City": { "type": "object", "properties": { @@ -4906,14 +4937,26 @@ "city_id": { "type": "integer" }, + "client_level": { + "$ref": "#/definitions/model.ClientLevel" + }, "client_level_id": { "type": "integer" + }, + "client_origin": { + "$ref": "#/definitions/model.ClientOrigin" }, "client_origin_id": { "type": "integer" }, + "client_status": { + "$ref": "#/definitions/model.ClientStatus" + }, "client_status_id": { "type": "integer" + }, + "client_type": { + "$ref": "#/definitions/model.ClientType" }, "client_type_id": { "type": "integer" @@ -6051,6 +6094,13 @@ "model.User": { "type": "object", "properties": { + "authority": { + "$ref": "#/definitions/model.Authority" + }, + "authorityId": { + "description": "鐢ㄦ埛瑙掕壊ID", + "type": "integer" + }, "companyName": { "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 616f200..5d4b73c 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -60,6 +60,22 @@ msg: type: string type: object + model.Authority: + properties: + authorityName: + description: 瑙掕壊鍚� + type: string + defaultRouter: + description: 榛樿鑿滃崟(榛樿dashboard) + type: string + id: + description: 瑙掕壊ID + type: integer + menus: + items: + $ref: '#/definitions/model.Menu' + type: array + type: object model.City: properties: id: @@ -79,12 +95,20 @@ $ref: '#/definitions/model.City' city_id: type: integer + client_level: + $ref: '#/definitions/model.ClientLevel' client_level_id: type: integer + client_origin: + $ref: '#/definitions/model.ClientOrigin' client_origin_id: type: integer + client_status: + $ref: '#/definitions/model.ClientStatus' client_status_id: type: integer + client_type: + $ref: '#/definitions/model.ClientType' client_type_id: type: integer contacts: @@ -831,6 +855,11 @@ type: object model.User: properties: + authority: + $ref: '#/definitions/model.Authority' + authorityId: + description: 鐢ㄦ埛瑙掕壊ID + type: integer companyName: type: string createAt: @@ -2992,6 +3021,11 @@ - City /api/city/list: get: + parameters: + - description: 鐪佷唤ID + in: query + name: provinceId + type: integer produces: - application/json responses: diff --git a/model/city.go b/model/city.go index d688573..4bfa0e7 100644 --- a/model/city.go +++ b/model/city.go @@ -39,6 +39,9 @@ if slf.Name != "" { db = db.Where("name = ?", slf.Name) } + if slf.ProvinceId != 0 { + db = db.Where("province_id = ?", slf.ProvinceId) + } return db } @@ -71,6 +74,11 @@ return slf } +func (slf *CitySearch) SetProvinceId(provinceId int) *CitySearch { + slf.ProvinceId = provinceId + return slf +} + func (slf *CitySearch) SetName(name string) *CitySearch { slf.Name = name return slf diff --git a/router/index.go b/router/index.go index 16abfb3..cdac9d3 100644 --- a/router/index.go +++ b/router/index.go @@ -3,7 +3,6 @@ import ( "aps_crm/conf" _ "aps_crm/docs" - "aps_crm/middleware" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" @@ -80,7 +79,7 @@ } PrivateGroup := Router.Group("api") - PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) + //PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) //PrivateGroup.Use(middleware.JWTAuth()) //PrivateGroup.Use(middleware.CasbinHandler()) { diff --git a/service/city.go b/service/city.go index 97eb035..bf9d9f0 100644 --- a/service/city.go +++ b/service/city.go @@ -56,14 +56,21 @@ return ecode.OK } -func (CityService) ListCities() ([]*model.City, int) { +func (CityService) ListCities(id int) ([]*model.City, int) { // get city list - list, err := model.NewCitySearch().FindAll() - if err != nil { - return nil, ecode.CityListErr + if id != 0 { + list, err := model.NewCitySearch().SetProvinceId(id).FindAll() + if err != nil { + return nil, ecode.CityListErr + } + return list, ecode.OK + } else { + list, err := model.NewCitySearch().FindAll() + if err != nil { + return nil, ecode.CityListErr + } + return list, ecode.OK } - - return list, ecode.OK } func (CityService) DeleteCity(id int) int { -- Gitblit v1.8.0