feat: gateway status.
This commit is contained in:
+18
-1
@@ -37,11 +37,28 @@ func NewGatewayAdminController() *GatewayAdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List 获取网关列表
|
// List 获取网关列表
|
||||||
// GET /api/gateways?keyword=&isSold=&projectType=®ionId=
|
// GET /api/v1/gateways?keyword=&isSold=&projectType=®ionId=
|
||||||
|
// 超级管理员可查询全部;操作员/区域管理员仅能查询所属 regionIDs 的网关
|
||||||
func (gc *GatewayAdminController) List(c *gin.Context) {
|
func (gc *GatewayAdminController) List(c *gin.Context) {
|
||||||
var items []models.Gateway
|
var items []models.Gateway
|
||||||
query := gc.DB.Model(&models.Gateway{}).Order("region_id ASC, created_at DESC")
|
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 != "" {
|
if keyword := strings.TrimSpace(c.Query("keyword")); keyword != "" {
|
||||||
likeValue := "%" + keyword + "%"
|
likeValue := "%" + keyword + "%"
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ func SetupRouter() *gin.Engine {
|
|||||||
public.POST("/register", controllers.Register)
|
public.POST("/register", controllers.Register)
|
||||||
public.POST("/login", controllers.Login)
|
public.POST("/login", controllers.Login)
|
||||||
}
|
}
|
||||||
|
v1.GET("/gateways", middleware.JWTAuth(), middleware.RequireOperatorOrHigher(), gatewayController.List)
|
||||||
v1.GET("/gateways/by-mac", middleware.JWTAuth(), middleware.RequireOperatorOrHigher(), gatewayController.GetByMACForUser)
|
v1.GET("/gateways/by-mac", middleware.JWTAuth(), middleware.RequireOperatorOrHigher(), gatewayController.GetByMACForUser)
|
||||||
|
|
||||||
auth := v1.Group("/auth")
|
auth := v1.Group("/auth")
|
||||||
|
|||||||
Reference in New Issue
Block a user