From 6fb16aa12c480c1cf7a7e343fb2368fac9852a84 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 16 Nov 2023 14:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...shandler.go => getorganizationshandler.go} | 6 ++--- server/ldap-admin/internal/handler/routes.go | 4 +-- ...mentslogic.go => getorganizationslogic.go} | 18 ++++++++----- server/ldap-admin/internal/types/types.go | 24 ----------------- server_api/ldap-admin.api | 26 ++----------------- 5 files changed, 19 insertions(+), 59 deletions(-) rename server/ldap-admin/internal/handler/{getdepartmentshandler.go => getorganizationshandler.go} (75%) rename server/ldap-admin/internal/logic/{getdepartmentslogic.go => getorganizationslogic.go} (82%) diff --git a/server/ldap-admin/internal/handler/getdepartmentshandler.go b/server/ldap-admin/internal/handler/getorganizationshandler.go similarity index 75% rename from server/ldap-admin/internal/handler/getdepartmentshandler.go rename to server/ldap-admin/internal/handler/getorganizationshandler.go index 8a5bf393..590e1a33 100644 --- a/server/ldap-admin/internal/handler/getdepartmentshandler.go +++ b/server/ldap-admin/internal/handler/getorganizationshandler.go @@ -11,7 +11,7 @@ import ( "fusenapi/server/ldap-admin/internal/types" ) -func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func GetOrganizationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.Request @@ -21,12 +21,12 @@ func GetDepartmentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } // 创建一个业务逻辑层实例 - l := logic.NewGetDepartmentsLogic(r.Context(), svcCtx) + l := logic.NewGetOrganizationsLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.GetDepartments(&req, userinfo) + resp := l.GetOrganizations(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/ldap-admin/internal/handler/routes.go b/server/ldap-admin/internal/handler/routes.go index 8d051164..05e78360 100644 --- a/server/ldap-admin/internal/handler/routes.go +++ b/server/ldap-admin/internal/handler/routes.go @@ -44,8 +44,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/api/ldap-admin/get_departments", - Handler: GetDepartmentsHandler(serverCtx), + Path: "/api/ldap-admin/get_organizations", + Handler: GetOrganizationsHandler(serverCtx), }, { Method: http.MethodPost, diff --git a/server/ldap-admin/internal/logic/getdepartmentslogic.go b/server/ldap-admin/internal/logic/getorganizationslogic.go similarity index 82% rename from server/ldap-admin/internal/logic/getdepartmentslogic.go rename to server/ldap-admin/internal/logic/getorganizationslogic.go index 20c0b630..d009ac02 100644 --- a/server/ldap-admin/internal/logic/getdepartmentslogic.go +++ b/server/ldap-admin/internal/logic/getorganizationslogic.go @@ -1,27 +1,28 @@ package logic import ( - "context" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/ldap_lib" "sort" "strings" + "context" + "fusenapi/server/ldap-admin/internal/svc" "fusenapi/server/ldap-admin/internal/types" "github.com/zeromicro/go-zero/core/logx" ) -type GetDepartmentsLogic struct { +type GetOrganizationsLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDepartmentsLogic { - return &GetDepartmentsLogic{ +func NewGetOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrganizationsLogic { + return &GetOrganizationsLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -29,7 +30,7 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge } // 处理进入前逻辑w,r -// func (l *GetDepartmentsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *GetOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } type DNItem struct { Attribute map[string]interface{} `json:"attribute"` @@ -39,7 +40,7 @@ type DNItem struct { Child []*DNItem `json:"child"` } -func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *GetOrganizationsLogic) GetOrganizations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { //从ldap获取组织架构数据 rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",") if len(rootCn) == 0 { @@ -112,3 +113,8 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth. } return resp.SetStatusWithMessage(basic.CodeOK, "", list) } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *GetOrganizationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/ldap-admin/internal/types/types.go b/server/ldap-admin/internal/types/types.go index 5c65fbe3..467148e4 100644 --- a/server/ldap-admin/internal/types/types.go +++ b/server/ldap-admin/internal/types/types.go @@ -19,30 +19,6 @@ type SaveApiReq struct { Remark string `json:"remark"` } -type GetDepartmentsRsp struct { - List []*DepartmentsItem `json:"list"` -} - -type DepartmentsItem struct { - Id int64 `json:"id"` - Name string `json:"name"` - Remark string `json:"remark"` - Type string `json:"type"` - ParentId int64 `json:"parent_id"` - Dn string `json:"dn"` - SyncState int64 `json:"sync_state"` - Sort int64 `json:"sort"` - Child []*DepartmentsItem `json:"child"` - Members []Member `json:"members"` -} - -type Member struct { - Id int64 `json:"id"` - Name string `json:"name"` - Nickname string `json:"nickname"` - Email string `json:"email"` -} - type SaveMenuReq struct { Id int64 `json:"id"` Name string `json:"name"` diff --git a/server_api/ldap-admin.api b/server_api/ldap-admin.api index 88e479e7..0215e8dd 100644 --- a/server_api/ldap-admin.api +++ b/server_api/ldap-admin.api @@ -31,8 +31,8 @@ service ldap-admin { @handler GetMenusHandler get /api/ldap-admin/get_menus(GetMenusReq) returns (response); //获取ldap组织列表 - @handler GetDepartmentsHandler - get /api/ldap-admin/get_departments(request) returns (response); + @handler GetOrganizationsHandler + get /api/ldap-admin/get_organizations(request) returns (response); //增加ldap组织 @handler CreateLdapOrganizationHandler post /api/ldap-admin/create_ldap_orgination(CreateLdapOrganizationReq) returns (response); @@ -58,28 +58,6 @@ type SaveApiReq { Remark string `json:"remark"` } -//获取部门列表 -type GetDepartmentsRsp { - List []*DepartmentsItem `json:"list"` -} -type DepartmentsItem { - Id int64 `json:"id"` - Name string `json:"name"` - Remark string `json:"remark"` - Type string `json:"type"` - ParentId int64 `json:"parent_id"` - Dn string `json:"dn"` - SyncState int64 `json:"sync_state"` - Sort int64 `json:"sort"` - Child []*DepartmentsItem `json:"child"` - Members []Member `json:"members"` -} -type Member { - Id int64 `json:"id"` - Name string `json:"name"` - Nickname string `json:"nickname"` - Email string `json:"email"` -} //保存菜单 type SaveMenuReq { Id int64 `json:"id"`