Documentation
¶
Index ¶
- type Module
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) ListResources(ctx context.Context) ([]mdk.MCPResource, error)
- func (m *Module) Models() []any
- func (m *Module) ReadResource(ctx context.Context, uri string) (string, error)
- func (m *Module) Repo() *Repository
- func (m *Module) Routes() []mdk.Route
- func (m *Module) Shutdown(ctx context.Context) error
- type Repository
- func (r *Repository) CreateTaxonomy(ctx context.Context, t *Taxonomy) error
- func (r *Repository) CreateTerm(ctx context.Context, term *TaxonomyTerm) error
- func (r *Repository) GetResourceIDsForTerm(ctx context.Context, termID, resourceType string) ([]string, error)
- func (r *Repository) GetTaxonomyByCode(ctx context.Context, code string) (*Taxonomy, error)
- func (r *Repository) GetTermBySlug(ctx context.Context, slug string) (*TaxonomyTerm, error)
- func (r *Repository) GetTermTree(ctx context.Context, taxonomyID string) ([]TaxonomyTerm, error)
- func (r *Repository) GetTermsForResource(ctx context.Context, resourceID, resourceType string) ([]TaxonomyTerm, error)
- func (r *Repository) LinkResource(ctx context.Context, termID, resourceID, resourceType string) error
- func (r *Repository) ListTaxonomies(ctx context.Context) ([]Taxonomy, error)
- func (r *Repository) UnlinkResource(ctx context.Context, termID, resourceID, resourceType string) error
- type Taxonomy
- type TaxonomyRelation
- type TaxonomyTerm
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements the mdk.Module interface for Taxonomy.
func (*Module) ListResources ¶
ListResources implements MCP list resources (empty).
func (*Module) ReadResource ¶
ReadResource implements MCP read resource (empty).
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository handles database queries for Taxonomy, TaxonomyTerm, and TaxonomyRelation.
func NewRepository ¶
func NewRepository(db *gorm.DB) *Repository
NewRepository creates a new taxonomy repository.
func (*Repository) CreateTaxonomy ¶
func (r *Repository) CreateTaxonomy(ctx context.Context, t *Taxonomy) error
CreateTaxonomy inserts a new taxonomy record.
func (*Repository) CreateTerm ¶
func (r *Repository) CreateTerm(ctx context.Context, term *TaxonomyTerm) error
CreateTerm inserts a new taxonomy term.
func (*Repository) GetResourceIDsForTerm ¶
func (r *Repository) GetResourceIDsForTerm(ctx context.Context, termID, resourceType string) ([]string, error)
GetResourceIDsForTerm retrieves all resource IDs of a specific type linked to a term.
func (*Repository) GetTaxonomyByCode ¶
GetTaxonomyByCode retrieves a taxonomy by its unique code.
func (*Repository) GetTermBySlug ¶
func (r *Repository) GetTermBySlug(ctx context.Context, slug string) (*TaxonomyTerm, error)
GetTermBySlug retrieves a taxonomy term by its slug.
func (*Repository) GetTermTree ¶
func (r *Repository) GetTermTree(ctx context.Context, taxonomyID string) ([]TaxonomyTerm, error)
GetTermTree builds and retrieves the nested terms hierarchy for a taxonomy.
func (*Repository) GetTermsForResource ¶
func (r *Repository) GetTermsForResource(ctx context.Context, resourceID, resourceType string) ([]TaxonomyTerm, error)
GetTermsForResource retrieves all terms linked to a resource.
func (*Repository) LinkResource ¶
func (r *Repository) LinkResource(ctx context.Context, termID, resourceID, resourceType string) error
LinkResource associates a resource with a taxonomy term.
func (*Repository) ListTaxonomies ¶
func (r *Repository) ListTaxonomies(ctx context.Context) ([]Taxonomy, error)
ListTaxonomies returns all taxonomies in the database.
func (*Repository) UnlinkResource ¶
func (r *Repository) UnlinkResource(ctx context.Context, termID, resourceID, resourceType string) error
UnlinkResource removes the association between a resource and a taxonomy term.
type Taxonomy ¶
type Taxonomy struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null" json:"name"`
Code string `gorm:"uniqueIndex;not null" json:"code"`
Type string `json:"type"` // e.g. "category", "tag", "collection", "brand"
Metadata mdk.Metadata `gorm:"type:text" json:"metadata"`
Terms []TaxonomyTerm `gorm:"foreignKey:TaxonomyID;constraint:OnDelete:CASCADE" json:"terms"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
Taxonomy represents a decoupled categorization system (e.g., categories, tags, collections, brands).
type TaxonomyRelation ¶
type TaxonomyRelation struct {
TermID string `gorm:"primaryKey" json:"term_id"`
ResourceID string `gorm:"primaryKey" json:"resource_id"`
ResourceType string `gorm:"primaryKey" json:"resource_type"` // e.g. "product", "page", "post"
}
TaxonomyRelation creates a polymorphic link between a term and any other entity (e.g. product).
type TaxonomyTerm ¶
type TaxonomyTerm struct {
ID string `gorm:"primaryKey" json:"id"`
TaxonomyID string `gorm:"index;not null" json:"taxonomy_id"`
ParentID *string `gorm:"index" json:"parent_id"`
Name string `gorm:"not null" json:"name"`
Slug string `gorm:"uniqueIndex;not null" json:"slug"`
Description string `json:"description"`
SEO seo.SEO `gorm:"embedded;embeddedPrefix:seo_"`
Metadata mdk.Metadata `gorm:"type:text" json:"metadata"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Children []TaxonomyTerm `gorm:"foreignKey:ParentID" json:"children,omitempty"`
}
TaxonomyTerm represents an individual hierarchical term inside a Taxonomy.
func (*TaxonomyTerm) BeforeCreate ¶
func (tt *TaxonomyTerm) BeforeCreate(tx *gorm.DB) error