Documentation
¶
Index ¶
- func NewMenuModule(logger logging.Logger, deps *core.Dependencies) core.Module
- func SetupMenuRoutes(r chi.Router, h *MenuHandler, jwtMiddleware func(http.Handler) http.Handler)
- type BatchCreateMenusInput
- type BatchMenuInput
- type BatchMenuInputMCP
- type BatchMenusResult
- type CreateMenuInput
- type CreateMenuRequest
- type DeleteMenuInput
- type GetMenuTreeInput
- type MCPServer
- type MenuHandler
- type MenuModule
- type MenuNode
- type MenuOutput
- type MenuService
- func (s *MenuService) BatchCreateMenus(ctx context.Context, inputs []BatchMenuInput) ([]*ent.Menu, error)
- func (s *MenuService) CreateMenu(ctx context.Context, input *ent.Menu) (*ent.Menu, error)
- func (s *MenuService) DeleteMenu(ctx context.Context, id uuid.UUID) error
- func (s *MenuService) GetAllMenus(ctx context.Context) ([]*ent.Menu, error)
- func (s *MenuService) GetMenuByID(ctx context.Context, id uuid.UUID) (*ent.Menu, error)
- func (s *MenuService) GetMenuTree(ctx context.Context, roleCodes []string, isSuperAdmin bool) ([]*MenuNode, error)
- func (s *MenuService) UpdateMenu(ctx context.Context, id uuid.UUID, input *ent.Menu) (*ent.Menu, error)
- type MenuTreeOutput
- type MenuTreeResult
- type UpdateMenuRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMenuModule ¶
func SetupMenuRoutes ¶
SetupMenuRoutes registers menu management routes.
Types ¶
type BatchCreateMenusInput ¶
type BatchCreateMenusInput struct {
Menus []BatchMenuInputMCP `json:"menus"`
}
type BatchMenuInput ¶
type BatchMenuInput struct {
TempID string `json:"tempId,omitempty"`
TempParentID string `json:"tempParentId,omitempty"`
Name string `json:"name"`
Path string `json:"path"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID *uuid.UUID `json:"parentId,omitempty"`
Sort int `json:"sort"`
Hidden bool `json:"hidden"`
Affix bool `json:"affix"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
}
BatchMenuInput represents a single menu in a batch create request. TempID and TempParentID enable parent-child references within the same batch.
type BatchMenuInputMCP ¶
type BatchMenuInputMCP struct {
TempID string `json:"tempId,omitempty"`
TempParentID string `json:"tempParentId,omitempty"`
Name string `json:"name"`
Path string `json:"path"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID string `json:"parentId,omitempty"`
Sort int `json:"sort"`
Hidden bool `json:"hidden"`
Affix bool `json:"affix"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
}
type BatchMenusResult ¶
type BatchMenusResult struct {
Menus []MenuOutput `json:"menus"`
Count int `json:"count"`
}
BatchMenusResult wraps a slice for MCP output (must be object type).
type CreateMenuInput ¶
type CreateMenuInput struct {
Name string `json:"name"`
Path string `json:"path"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID string `json:"parentId,omitempty"`
Sort int `json:"sort"`
Hidden bool `json:"hidden"`
Affix bool `json:"affix"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
}
type CreateMenuRequest ¶
type CreateMenuRequest struct {
Name string `json:"name" binding:"required"`
Path string `json:"path" binding:"required"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID *uuid.UUID `json:"parentId,omitempty"`
Sort int `json:"sort"`
Hidden bool `json:"hidden"`
Affix bool `json:"affix"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
}
CreateMenuRequest represents the request body for creating a menu.
type DeleteMenuInput ¶
type DeleteMenuInput struct {
ID string `json:"id"`
}
type GetMenuTreeInput ¶
type GetMenuTreeInput struct{}
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer wraps the menu service as an MCP server
func NewMCPServer ¶
func NewMCPServer(service *MenuService, logger logging.Logger) (*MCPServer, error)
NewMCPServer creates a standalone MCP server for menu operations
func (*MCPServer) RegisterOn ¶
RegisterOn registers all menu tools and resources onto an external shared server.
type MenuHandler ¶
type MenuHandler struct {
// contains filtered or unexported fields
}
func NewMenuHandler ¶
func NewMenuHandler(menuService *MenuService, logger logging.Logger) *MenuHandler
func (*MenuHandler) CreateMenu ¶
func (h *MenuHandler) CreateMenu(w http.ResponseWriter, r *http.Request)
CreateMenu handles menu creation. @Summary Create a menu @Tags Menus @Accept json @Produce json @Param request body CreateMenuRequest true "Menu data" @Success 201 {object} ent.Menu @Failure 400 {object} responder.Error @Failure 500 {object} responder.Error @Router /menus [post]
func (*MenuHandler) DeleteMenu ¶
func (h *MenuHandler) DeleteMenu(w http.ResponseWriter, r *http.Request)
DeleteMenu handles menu deletion. @Summary Delete a menu @Tags Menus @Accept json @Produce json @Param id path string true "Menu ID" @Success 200 {object} map[string]string @Failure 400 {object} responder.Error @Failure 500 {object} responder.Error @Router /menus/{id} [delete]
func (*MenuHandler) GetMenuTree ¶
func (h *MenuHandler) GetMenuTree(w http.ResponseWriter, r *http.Request)
GetMenuTree handles getting menu tree based on user's RBAC permissions. @Summary Get menu tree for current user @Description Returns menu tree filtered by user's role permissions. Super admin sees all menus. @Tags Menus @Accept json @Produce json @Success 200 {object} []MenuNode @Failure 401 {object} responder.Error @Failure 500 {object} responder.Error @Router /menus/tree [get]
func (*MenuHandler) UpdateMenu ¶
func (h *MenuHandler) UpdateMenu(w http.ResponseWriter, r *http.Request)
UpdateMenu handles menu updates. @Summary Update a menu @Tags Menus @Accept json @Produce json @Param id path string true "Menu ID" @Param request body UpdateMenuRequest true "Menu data" @Success 200 {object} ent.Menu @Failure 400 {object} responder.Error @Failure 500 {object} responder.Error @Router /menus/{id} [put]
type MenuModule ¶
type MenuModule struct {
// contains filtered or unexported fields
}
func (*MenuModule) Name ¶
func (m *MenuModule) Name() string
func (*MenuModule) RegisterPrivateRoutes ¶
func (m *MenuModule) RegisterPrivateRoutes(r chi.Router)
RegisterPrivateRoutes registers protected menu endpoints
func (*MenuModule) RegisterPublicRoutes ¶
func (m *MenuModule) RegisterPublicRoutes(r chi.Router)
RegisterPublicRoutes - menu module has no public routes
type MenuOutput ¶
type MenuOutput struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID uuid.UUID `json:"parentId,omitempty"`
Sort int `json:"sort"`
Hidden bool `json:"hidden"`
Affix bool `json:"affix"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
MenuOutput is a flat DTO for MCP tool outputs, free of ent Edge cycles.
type MenuService ¶
type MenuService struct {
// contains filtered or unexported fields
}
func NewMenuService ¶
func NewMenuService(client *ent.Client, logger logging.Logger) *MenuService
func (*MenuService) BatchCreateMenus ¶
func (s *MenuService) BatchCreateMenus(ctx context.Context, inputs []BatchMenuInput) ([]*ent.Menu, error)
BatchCreateMenus creates multiple menus in a single transaction. Supports parent-child relationships within the same batch via tempId references. Each input menu can have a TempID field and a TempParentID field: - TempID: a client-assigned identifier for referencing within this batch - TempParentID: references another menu's TempID in this batch as its parent
func (*MenuService) CreateMenu ¶
CreateMenu creates a new menu item
func (*MenuService) DeleteMenu ¶
DeleteMenu deletes a menu and recursively deletes its children
func (*MenuService) GetAllMenus ¶
GetAllMenus retrieves all menus ordered by sort field
func (*MenuService) GetMenuByID ¶
GetMenuByID retrieves a single menu by ID
func (*MenuService) GetMenuTree ¶
func (s *MenuService) GetMenuTree(ctx context.Context, roleCodes []string, isSuperAdmin bool) ([]*MenuNode, error)
GetMenuTree returns the menu tree based on user roles from context. Super admin roles see all menus, others see only menus assigned to their roles.
type MenuTreeOutput ¶
type MenuTreeOutput struct {
MenuOutput
Children []MenuTreeOutput `json:"children,omitempty"`
}
MenuTreeOutput is a tree DTO for MCP tool outputs.
type MenuTreeResult ¶
MenuTreeResult is a simple metadata output for the tree tool. The full tree JSON is returned via TextContent to avoid recursive type cycles.
type UpdateMenuRequest ¶
type UpdateMenuRequest struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Component string `json:"component,omitempty"`
Redirect string `json:"redirect,omitempty"`
Icon string `json:"icon,omitempty"`
ParentID *uuid.UUID `json:"parentId,omitempty"`
Sort int `json:"sort,omitempty"`
Hidden bool `json:"hidden,omitempty"`
Affix bool `json:"affix,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
Params []string `json:"params,omitempty"`
}
UpdateMenuRequest represents the request body for updating a menu.