- api/admin/v1 拆 base/system/admin 三子包,路由前缀 /admin/v1/{base,system,admin}
- system: auth/menu/role;admin: 管理员;base: log
- controller 改 import 子包;006_menu_paths_v2.sql 更新接口路径映射
- 权限码与路由分离,permission 标识不变
- 冒烟测试新路径 8 接口全通过
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
|
|
systemv1 "service.xpcool.com/api/admin/v1/system"
|
|
"service.xpcool.com/internal/model/dto"
|
|
"service.xpcool.com/internal/service"
|
|
)
|
|
|
|
// 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 *systemv1.InfoReq) (res *systemv1.InfoRes, err error) {
|
|
info, err := service.AdminAuth().Info(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &systemv1.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 *systemv1.CodesReq) (res *systemv1.CodesRes, err error) {
|
|
codes, err := service.AdminAuth().Codes(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &systemv1.CodesRes{Codes: codes}, nil
|
|
}
|
|
|
|
// Routes returns the current administrator's visible menu tree as vben routes.
|
|
func (c *ProfileController) Routes(ctx context.Context, req *systemv1.MenuRoutesReq) (res *systemv1.MenuRoutesRes, err error) {
|
|
routes, err := service.AdminMenu().Routes(ctx, adminID(ctx))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]*systemv1.RouteItem, 0, len(routes))
|
|
for _, r := range routes {
|
|
out = append(out, toV1Route(r))
|
|
}
|
|
return &systemv1.MenuRoutesRes{Routes: out}, nil
|
|
}
|
|
|
|
// toV1Route converts a dto route tree into the v1 API shape.
|
|
func toV1Route(r *dto.RouteItem) *systemv1.RouteItem {
|
|
item := &systemv1.RouteItem{
|
|
Name: r.Name,
|
|
Path: r.Path,
|
|
Component: r.Component,
|
|
Meta: systemv1.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
|
|
}
|