feat: gateway status.

This commit is contained in:
2026-05-02 08:43:01 +08:00
parent cd490eea36
commit 6ef84b7488
2 changed files with 19 additions and 1 deletions
+18 -1
View File
@@ -37,11 +37,28 @@ func NewGatewayAdminController() *GatewayAdminController {
}
// List 获取网关列表
// GET /api/gateways?keyword=&isSold=&projectType=&regionId=
// GET /api/v1/gateways?keyword=&isSold=&projectType=&regionId=
// 超级管理员可查询全部;操作员/区域管理员仅能查询所属 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 + "%"
+1
View File
@@ -135,6 +135,7 @@ func SetupRouter() *gin.Engine {
public.POST("/register", controllers.Register)
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)
auth := v1.Group("/auth")