增加添加部门接口

This commit is contained in:
laodaming 2023-11-16 14:29:24 +08:00
parent 6fb16aa12c
commit c7ca444fe7
11 changed files with 75 additions and 75 deletions

View File

@ -11,22 +11,22 @@ import (
"fusenapi/server/ldap-admin/internal/types"
)
func CreateLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func CreateLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateLdapOrganizationReq
var req types.CreateLdapOrginationReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewCreateLdapOrganizationLogic(r.Context(), svcCtx)
l := logic.NewCreateLdapOrginationLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.CreateLdapOrganization(&req, userinfo)
resp := l.CreateLdapOrgination(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)

View File

@ -11,22 +11,22 @@ import (
"fusenapi/server/ldap-admin/internal/types"
)
func DeleteLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func DeleteLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteLdapOrganizationReq
var req types.DeleteLdapOrginationReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewDeleteLdapOrganizationLogic(r.Context(), svcCtx)
l := logic.NewDeleteLdapOrginationLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.DeleteLdapOrganization(&req, userinfo)
resp := l.DeleteLdapOrgination(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)

View File

@ -11,7 +11,7 @@ import (
"fusenapi/server/ldap-admin/internal/types"
)
func GetOrganizationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func GetorginationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
@ -21,12 +21,12 @@ func GetOrganizationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
// 创建一个业务逻辑层实例
l := logic.NewGetOrganizationsLogic(r.Context(), svcCtx)
l := logic.NewGetorginationsLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetOrganizations(&req, userinfo)
resp := l.Getorginations(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)

View File

@ -44,23 +44,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodGet,
Path: "/api/ldap-admin/get_organizations",
Handler: GetOrganizationsHandler(serverCtx),
Path: "/api/ldap-admin/get_ldap_orginations",
Handler: GetorginationsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/create_ldap_orgination",
Handler: CreateLdapOrganizationHandler(serverCtx),
Handler: CreateLdapOrginationHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/delete_ldap_orgination",
Handler: DeleteLdapOrganizationHandler(serverCtx),
Handler: DeleteLdapOrginationHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/update_ldap_orgination",
Handler: UpdateLdapOrganizationHandler(serverCtx),
Handler: UpdateLdapOrginationHandler(serverCtx),
},
},
)

View File

@ -11,22 +11,22 @@ import (
"fusenapi/server/ldap-admin/internal/types"
)
func UpdateLdapOrganizationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func UpdateLdapOrginationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UpdateLdapOrganizationReq
var req types.UpdateLdapOrginationReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewUpdateLdapOrganizationLogic(r.Context(), svcCtx)
l := logic.NewUpdateLdapOrginationLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.UpdateLdapOrganization(&req, userinfo)
resp := l.UpdateLdapOrgination(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)

View File

@ -14,14 +14,14 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type CreateLdapOrganizationLogic struct {
type CreateLdapOrginationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapOrganizationLogic {
return &CreateLdapOrganizationLogic{
func NewCreateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLdapOrginationLogic {
return &CreateLdapOrginationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
@ -29,31 +29,31 @@ func NewCreateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
// 处理进入前逻辑w,r
// func (l *CreateLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// func (l *CreateLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.OrganizationOu = strings.Trim(req.OrganizationOu, " ")
req.ParentOrganizationDN = strings.Trim(req.ParentOrganizationDN, " ")
func (l *CreateLdapOrginationLogic) CreateLdapOrgination(req *types.CreateLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
req.OrginationOu = strings.Trim(req.OrginationOu, " ")
req.ParentOrginationDN = strings.Trim(req.ParentOrginationDN, " ")
req.BusinessCategory = strings.Trim(req.BusinessCategory, " ")
if req.OrganizationOu == "" {
if req.OrginationOu == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,organization_ou不能为空")
}
if len(strings.Split(req.OrganizationOu, ",")) != 1 {
if len(strings.Split(req.OrginationOu, ",")) != 1 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,不合法的organization_ou")
}
if req.ParentOrganizationDN == "" {
if req.ParentOrginationDN == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,parentOrganization_dn不能为空")
}
if req.BusinessCategory == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数错误,business_category不能为空")
}
//组装organization dn
organizationDN := "ou=" + req.OrganizationOu + "," + req.ParentOrganizationDN
organizationDN := "ou=" + req.OrginationOu + "," + req.ParentOrginationDN
ldapServer := ldap_lib.NewLdap(l.svcCtx.Ldap, l.svcCtx.Config.Ldap.BaseDN, l.svcCtx.Config.Ldap.RootDN)
err := ldapServer.Create(organizationDN, map[string][]string{
"objectClass": {"top", "organizationalUnit"},
"ou": {req.OrganizationOu},
"ou": {req.OrginationOu},
"businessCategory": {req.BusinessCategory},
})
if err != nil {
@ -64,6 +64,6 @@ func (l *CreateLdapOrganizationLogic) CreateLdapOrganization(req *types.CreateLd
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *CreateLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// func (l *CreateLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -12,14 +12,14 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateLdapOrganizationLogic struct {
type DeleteLdapOrginationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLdapOrganizationLogic {
return &UpdateLdapOrganizationLogic{
func NewDeleteLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLdapOrginationLogic {
return &DeleteLdapOrginationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
@ -27,10 +27,10 @@ func NewUpdateLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
// 处理进入前逻辑w,r
// func (l *UpdateLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// func (l *DeleteLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *DeleteLdapOrginationLogic) DeleteLdapOrgination(req *types.DeleteLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
@ -38,6 +38,6 @@ func (l *UpdateLdapOrganizationLogic) UpdateLdapOrganization(req *types.UpdateLd
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *UpdateLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// func (l *DeleteLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -15,14 +15,14 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrganizationsLogic struct {
type GetorginationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrganizationsLogic {
return &GetOrganizationsLogic{
func NewGetorginationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetorginationsLogic {
return &GetorginationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
@ -30,7 +30,7 @@ func NewGetOrganizationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
// 处理进入前逻辑w,r
// func (l *GetOrganizationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// func (l *GetorginationsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
type DNItem struct {
Attribute map[string]interface{} `json:"attribute"`
@ -40,7 +40,7 @@ type DNItem struct {
Child []*DNItem `json:"child"`
}
func (l *GetOrganizationsLogic) GetOrganizations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *GetorginationsLogic) Getorginations(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
//从ldap获取组织架构数据
rootCn := strings.Split(l.svcCtx.Config.Ldap.RootDN, ",")
if len(rootCn) == 0 {
@ -115,6 +115,6 @@ func (l *GetOrganizationsLogic) GetOrganizations(req *types.Request, userinfo *a
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetOrganizationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// func (l *GetorginationsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -12,14 +12,14 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteLdapOrganizationLogic struct {
type UpdateLdapOrginationLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLdapOrganizationLogic {
return &DeleteLdapOrganizationLogic{
func NewUpdateLdapOrginationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLdapOrginationLogic {
return &UpdateLdapOrginationLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
@ -27,10 +27,10 @@ func NewDeleteLdapOrganizationLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
// 处理进入前逻辑w,r
// func (l *DeleteLdapOrganizationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// func (l *UpdateLdapOrginationLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *DeleteLdapOrganizationLogic) DeleteLdapOrganization(req *types.DeleteLdapOrganizationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *UpdateLdapOrginationLogic) UpdateLdapOrgination(req *types.UpdateLdapOrginationReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
@ -38,6 +38,6 @@ func (l *DeleteLdapOrganizationLogic) DeleteLdapOrganization(req *types.DeleteLd
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *DeleteLdapOrganizationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// func (l *UpdateLdapOrginationLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -73,18 +73,18 @@ type MenuItem struct {
Status int64 `json:"status"`
}
type CreateLdapOrganizationReq struct {
OrganizationOu string `json:"organization_ou"` //组织ou
BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
type CreateLdapOrginationReq struct {
OrginationOu string `json:"orgination_ou"` //组织ou
BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrginationDN string `json:"parent_orgination_dn"` //父级dn
}
type DeleteLdapOrganizationReq struct {
OrganizationDN string `json:"organization_dn"` //组织dn
type DeleteLdapOrginationReq struct {
OrginationDN string `json:"orgination_dn"` //组织dn
}
type UpdateLdapOrganizationReq struct {
OrganizationDN string `json:"organization_dn"` //组织dn
type UpdateLdapOrginationReq struct {
OrginationDN string `json:"orgination_dn"` //组织dn
BusinessCategory string `json:"business_category"` //组织分类名称
}

View File

@ -31,17 +31,17 @@ service ldap-admin {
@handler GetMenusHandler
get /api/ldap-admin/get_menus(GetMenusReq) returns (response);
//获取ldap组织列表
@handler GetOrganizationsHandler
get /api/ldap-admin/get_organizations(request) returns (response);
@handler GetorginationsHandler
get /api/ldap-admin/get_ldap_orginations(request) returns (response);
//增加ldap组织
@handler CreateLdapOrganizationHandler
post /api/ldap-admin/create_ldap_orgination(CreateLdapOrganizationReq) returns (response);
@handler CreateLdapOrginationHandler
post /api/ldap-admin/create_ldap_orgination(CreateLdapOrginationReq) returns (response);
//删除ldap组织
@handler DeleteLdapOrganizationHandler
post /api/ldap-admin/delete_ldap_orgination(DeleteLdapOrganizationReq) returns (response);
@handler DeleteLdapOrginationHandler
post /api/ldap-admin/delete_ldap_orgination(DeleteLdapOrginationReq) returns (response);
//修改组织
@handler UpdateLdapOrganizationHandler
post /api/ldap-admin/update_ldap_orgination(UpdateLdapOrganizationReq) returns (response);
@handler UpdateLdapOrginationHandler
post /api/ldap-admin/update_ldap_orgination(UpdateLdapOrginationReq) returns (response);
}
type GetApisReq {
@ -110,17 +110,17 @@ type MenuItem {
Status int64 `json:"status"`
}
//增加ldap组织
type CreateLdapOrganizationReq {
OrganizationOu string `json:"organization_ou"` //组织ou
BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrganizationDN string `json:"parent_organization_dn"` //父级dn
type CreateLdapOrginationReq {
OrginationOu string `json:"orgination_ou"` //组织ou
BusinessCategory string `json:"business_category"` //组织分类名称
ParentOrginationDN string `json:"parent_orgination_dn"` //父级dn
}
//删除ldap组织
type DeleteLdapOrganizationReq {
OrganizationDN string `json:"organization_dn"` //组织dn
type DeleteLdapOrginationReq {
OrginationDN string `json:"orgination_dn"` //组织dn
}
//修改ldap组织
type UpdateLdapOrganizationReq {
OrganizationDN string `json:"organization_dn"` //组织dn
type UpdateLdapOrginationReq {
OrginationDN string `json:"orgination_dn"` //组织dn
BusinessCategory string `json:"business_category"` //组织分类名称
}