menu

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMenuModule

func NewMenuModule(logger logging.Logger, deps *core.Dependencies) core.Module

func SetupMenuRoutes

func SetupMenuRoutes(r chi.Router, h *MenuHandler, jwtMiddleware func(http.Handler) http.Handler)

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) GetServer

func (s *MCPServer) GetServer() *mcp.Server

GetServer returns the underlying MCP server

func (*MCPServer) RegisterOn

func (s *MCPServer) RegisterOn(server *mcp.Server) error

RegisterOn registers all menu tools and resources onto an external shared server.

func (*MCPServer) Run

func (s *MCPServer) Run(ctx context.Context) error

Run starts the MCP server using stdio transport

type MenuHandler struct {
	// contains filtered or unexported fields
}

func NewMenuHandler

func NewMenuHandler(menuService *MenuService, logger logging.Logger) *MenuHandler
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 (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 (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 (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 struct {
	// contains filtered or unexported fields
}
func (m *MenuModule) Name() string
func (m *MenuModule) RegisterPrivateRoutes(r chi.Router)

RegisterPrivateRoutes registers protected menu endpoints

func (m *MenuModule) RegisterPublicRoutes(r chi.Router)

RegisterPublicRoutes - menu module has no public routes

type MenuNode struct {
	*ent.Menu
	Children []*MenuNode `json:"children,omitempty"`
}

MenuNode represents a menu in a tree structure

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 struct {
	// contains filtered or unexported fields
}

func NewMenuService

func NewMenuService(client *ent.Client, logger logging.Logger) *MenuService
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 (s *MenuService) CreateMenu(ctx context.Context, input *ent.Menu) (*ent.Menu, error)

CreateMenu creates a new menu item

func (s *MenuService) DeleteMenu(ctx context.Context, id uuid.UUID) error

DeleteMenu deletes a menu and recursively deletes its children

func (s *MenuService) GetAllMenus(ctx context.Context) ([]*ent.Menu, error)

GetAllMenus retrieves all menus ordered by sort field

func (s *MenuService) GetMenuByID(ctx context.Context, id uuid.UUID) (*ent.Menu, error)

GetMenuByID retrieves a single menu by ID

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.

func (s *MenuService) UpdateMenu(ctx context.Context, id uuid.UUID, input *ent.Menu) (*ent.Menu, error)

UpdateMenu updates an existing menu

type MenuTreeOutput struct {
	MenuOutput
	Children []MenuTreeOutput `json:"children,omitempty"`
}

MenuTreeOutput is a tree DTO for MCP tool outputs.

type MenuTreeResult struct {
	RootCount  int `json:"rootCount"`
	TotalCount int `json:"totalCount"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL