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.
43 lines
897 B
43 lines
897 B
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package menu
|
|
|
|
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 GetMenuListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取全部菜单列表
|
|
func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuListLogic {
|
|
return &GetMenuListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetMenuListLogic) GetMenuList() (resp *types.MenuListResponse, err error) {
|
|
menus, err := model.MenuFindAll(l.ctx, l.svcCtx.DB)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("获取菜单列表失败: %v", err)
|
|
}
|
|
|
|
tree := buildMenuTree(menus, 0)
|
|
|
|
return &types.MenuListResponse{
|
|
List: tree,
|
|
}, nil
|
|
}
|
|
|