fix
Add a request field to get the city information based on the province id
| | |
| | | type CityApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags City |
| | | // @Summary 添加城市 |
| | | // @Produce application/json |
| | |
| | | } |
| | | |
| | | // Set |
| | | // |
| | | // @Tags City |
| | | // @Summary 设置城市 |
| | | // @Produce application/json |
| | |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @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) { |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags City |
| | | // @Summary 删除城市 |
| | | // @Produce application/json |
| | |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags City |
| | | // @Summary 更新城市 |
| | | // @Produce application/json |
| | |
| | | "City" |
| | | ], |
| | | "summary": "获取城市列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "省份ID", |
| | | "name": "provinceId", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | "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" |
| | |
| | | "model.User": { |
| | | "type": "object", |
| | | "properties": { |
| | | "authority": { |
| | | "$ref": "#/definitions/model.Authority" |
| | | }, |
| | | "authorityId": { |
| | | "description": "用户角色ID", |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "City" |
| | | ], |
| | | "summary": "获取城市列表", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "省份ID", |
| | | "name": "provinceId", |
| | | "in": "query" |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "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": { |
| | |
| | | "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" |
| | |
| | | "model.User": { |
| | | "type": "object", |
| | | "properties": { |
| | | "authority": { |
| | | "$ref": "#/definitions/model.Authority" |
| | | }, |
| | | "authorityId": { |
| | | "description": "用户角色ID", |
| | | "type": "integer" |
| | | }, |
| | | "companyName": { |
| | | "type": "string" |
| | | }, |
| | |
| | | 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: |
| | |
| | | $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: |
| | |
| | | type: object |
| | | model.User: |
| | | properties: |
| | | authority: |
| | | $ref: '#/definitions/model.Authority' |
| | | authorityId: |
| | | description: 用户角色ID |
| | | type: integer |
| | | companyName: |
| | | type: string |
| | | createAt: |
| | |
| | | - City |
| | | /api/city/list: |
| | | get: |
| | | parameters: |
| | | - description: 省份ID |
| | | in: query |
| | | name: provinceId |
| | | type: integer |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | if slf.ProvinceId != 0 { |
| | | db = db.Where("province_id = ?", slf.ProvinceId) |
| | | } |
| | | |
| | | return db |
| | | } |
| | |
| | | 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 |
| | |
| | | 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" |
| | |
| | | } |
| | | |
| | | 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()) |
| | | { |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (CityService) ListCities() ([]*model.City, int) { |
| | | func (CityService) ListCities(id int) ([]*model.City, int) { |
| | | // get city list |
| | | 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 |
| | | } |
| | | } |
| | | |
| | | func (CityService) DeleteCity(id int) int { |
| | | // check city exist |