From 694c43292a49f944be670dbc388f1cafc2fe0e22 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Thu, 9 Nov 2023 20:07:30 +0800 Subject: [PATCH] add api: /api/n9e/user/busi-groups --- center/router/router.go | 3 +++ center/router/router_user.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/center/router/router.go b/center/router/router.go index b3b6513b2..bfc644343 100644 --- a/center/router/router.go +++ b/center/router/router.go @@ -407,6 +407,9 @@ func (rt *Router) Config(r *gin.Engine) { pages.GET("/config", rt.auth(), rt.admin(), rt.configGetByKey) pages.PUT("/config", rt.auth(), rt.admin(), rt.configPutByKey) + // for admin api + pages.GET("/user/busi-groups", rt.auth(), rt.admin(), rt.userBusiGroupsGets) + } r.GET("/api/n9e/versions", func(c *gin.Context) { diff --git a/center/router/router_user.go b/center/router/router_user.go index d28c91340..5e8f366ca 100644 --- a/center/router/router_user.go +++ b/center/router/router_user.go @@ -11,6 +11,28 @@ import ( "github.com/toolkits/pkg/ginx" ) +func (rt *Router) userBusiGroupsGets(c *gin.Context) { + userid := ginx.QueryInt64(c, "userid", 0) + username := ginx.QueryStr(c, "username", "") + + if userid == 0 && username == "" { + ginx.Bomb(http.StatusBadRequest, "userid or username required") + } + + var user *models.User + var err error + if userid > 0 { + user, err = models.UserGetById(rt.Ctx, userid) + } else { + user, err = models.UserGetByUsername(rt.Ctx, username) + } + + ginx.Dangerous(err) + + groups, err := user.BusiGroups(rt.Ctx, 10000, "") + ginx.NewRender(c).Data(groups, err) +} + func (rt *Router) userFindAll(c *gin.Context) { list, err := models.UserGetAll(rt.Ctx) ginx.NewRender(c).Data(list, err)