feat: gateway status.
This commit is contained in:
+18
-1
@@ -37,11 +37,28 @@ func NewGatewayAdminController() *GatewayAdminController {
|
||||
}
|
||||
|
||||
// List 获取网关列表
|
||||
// GET /api/gateways?keyword=&isSold=&projectType=®ionId=
|
||||
// GET /api/v1/gateways?keyword=&isSold=&projectType=®ionId=
|
||||
// 超级管理员可查询全部;操作员/区域管理员仅能查询所属 regionIDs 的网关
|
||||
func (gc *GatewayAdminController) List(c *gin.Context) {
|
||||
var items []models.Gateway
|
||||
query := gc.DB.Model(&models.Gateway{}).Order("region_id ASC, created_at DESC")
|
||||
|
||||
// 非超级管理员按用户区域过滤
|
||||
roleValue, _ := c.Get("role")
|
||||
role, _ := roleValue.(models.UserRole)
|
||||
if role != models.UserRoleSuperAdmin {
|
||||
regionIDs, err := getUserRegionIDsFromContext(c)
|
||||
if err != nil {
|
||||
writeError(c, http.StatusForbidden, err.Error())
|
||||
return
|
||||
}
|
||||
if len(regionIDs) == 0 {
|
||||
writeError(c, http.StatusForbidden, "当前用户未配置可访问区域")
|
||||
return
|
||||
}
|
||||
query = query.Where("region_id IN ?", regionIDs)
|
||||
}
|
||||
|
||||
// 模糊搜索
|
||||
if keyword := strings.TrimSpace(c.Query("keyword")); keyword != "" {
|
||||
likeValue := "%" + keyword + "%"
|
||||
|
||||
Reference in New Issue
Block a user