- 将 admin 相关服务移动到 internal/service/admin 目录下 - 更新控制器中的服务导入路径引用 - 移除已合并的服务文件 - 添加统一工作约定文档 - 更新 API 接口定义的包路径
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
|
|
authv1 "service.xpcool.com/api/admin/v1/system/auth"
|
|
menuv1 "service.xpcool.com/api/admin/v1/system/menu"
|
|
"service.xpcool.com/internal/model/dto"
|
|
"service.xpcool.com/internal/service/admin/system/auth"
|
|
"service.xpcool.com/internal/service/admin/system/menu"
|
|
)
|
|
|
|
// ProfileController exposes the logged-in admin's own profile endpoints
|
|
// (login-only, no X-Permission required). Bind behind AdminAuthOnly.
|
|
type ProfileController struct{}
|
|
|
|
// NewProfile creates the profile controller.
|
|
func NewProfile() *ProfileController { return &ProfileController{} }
|
|
|
|
// Info returns the current administrator profile.
|
|
func (c *ProfileController) Info(ctx context.Context, req *authv1.InfoReq) (res *authv1.InfoRes, err error) {
|
|
info, err := auth.AdminAuth().Info(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &authv1.InfoRes{AdminID: info.AdminID, Username: info.Username, Nickname: info.Nickname, Roles: info.Roles}, nil
|
|
}
|
|
|
|
// Codes returns the button-level permission codes of the current administrator.
|
|
func (c *ProfileController) Codes(ctx context.Context, req *authv1.CodesReq) (res *authv1.CodesRes, err error) {
|
|
codes, err := auth.AdminAuth().Codes(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &authv1.CodesRes{Codes: codes}, nil
|
|
}
|
|
|
|
// Routes returns the current administrator's visible menu tree as vben routes.
|
|
func (c *ProfileController) Routes(ctx context.Context, req *menuv1.MenuRoutesReq) (res *menuv1.MenuRoutesRes, err error) {
|
|
routes, err := menu.AdminMenu().Routes(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]*menuv1.RouteItem, 0, len(routes))
|
|
for _, r := range routes {
|
|
out = append(out, toV1Route(r))
|
|
}
|
|
return &menuv1.MenuRoutesRes{Routes: out}, nil
|
|
}
|
|
|
|
// toV1Route converts a dto route tree into the v1 API shape.
|
|
func toV1Route(r *dto.RouteItem) *menuv1.RouteItem {
|
|
item := &menuv1.RouteItem{
|
|
Name: r.Name,
|
|
Path: r.Path,
|
|
Component: r.Component,
|
|
Meta: menuv1.RouteMeta{
|
|
Title: r.Meta.Title,
|
|
Icon: r.Meta.Icon,
|
|
Order: r.Meta.Order,
|
|
Authority: r.Meta.Authority,
|
|
HideInMenu: r.Meta.HideInMenu,
|
|
},
|
|
}
|
|
for _, c := range r.Children {
|
|
item.Children = append(item.Children, toV1Route(c))
|
|
}
|
|
return item
|
|
}
|