You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package role
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type SetRoleMenusLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 设置角色菜单
|
|
func NewSetRoleMenusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetRoleMenusLogic {
|
|
return &SetRoleMenusLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *SetRoleMenusLogic) SetRoleMenus(req *types.SetRoleMenusRequest) (resp *types.Response, err error) {
|
|
// 验证角色是否存在
|
|
_, err = model.RoleFindOne(l.ctx, l.svcCtx.DB, req.Id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("角色不存在: %v", err)
|
|
}
|
|
|
|
// 全量设置角色的菜单
|
|
err = model.RoleMenuSetForRole(l.ctx, l.svcCtx.DB, req.Id, req.MenuIds)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("设置角色菜单失败: %v", err)
|
|
}
|
|
|
|
return &types.Response{
|
|
Code: 0,
|
|
Message: "设置成功",
|
|
Success: true,
|
|
}, nil
|
|
}
|
|
|