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.
56 lines
1.3 KiB
56 lines
1.3 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 GetRoleListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取角色列表
|
|
func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleListLogic {
|
|
return &GetRoleListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetRoleListLogic) GetRoleList() (resp *types.RoleListResponse, err error) {
|
|
roles, err := model.RoleFindAll(l.ctx, l.svcCtx.DB)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("获取角色列表失败: %v", err)
|
|
}
|
|
|
|
list := make([]types.RoleInfo, 0, len(roles))
|
|
for _, r := range roles {
|
|
list = append(list, types.RoleInfo{
|
|
Id: r.Id,
|
|
Name: r.Name,
|
|
Code: r.Code,
|
|
Description: r.Description,
|
|
IsSystem: r.IsSystem,
|
|
SortOrder: r.SortOrder,
|
|
Status: r.Status,
|
|
CreatedAt: r.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
UpdatedAt: r.UpdatedAt.Format("2006-01-02 15:04:05"),
|
|
})
|
|
}
|
|
|
|
return &types.RoleListResponse{
|
|
List: list,
|
|
}, nil
|
|
}
|
|
|