taxonomy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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 NewModule

func NewModule() *Module

NewModule creates a new instance of the taxonomy module.

func (*Module) ID

func (m *Module) ID() string

ID returns the unique identifier for the taxonomy module.

func (*Module) Init

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

Init initializes the repository and database connections.

func (*Module) ListResources

func (m *Module) ListResources(ctx context.Context) ([]mdk.MCPResource, error)

ListResources implements MCP list resources (empty).

func (*Module) Models

func (m *Module) Models() []any

Models returns instances of the taxonomy database schemas to migrate.

func (*Module) ReadResource

func (m *Module) ReadResource(ctx context.Context, uri string) (string, error)

ReadResource implements MCP read resource (empty).

func (*Module) Repo

func (m *Module) Repo() *Repository

Repo returns the taxonomy repository.

func (*Module) Routes

func (m *Module) Routes() []mdk.Route

Routes returns HTTP endpoints (none for this module).

func (*Module) Shutdown

func (m *Module) Shutdown(ctx context.Context) error

Shutdown performs cleanups when shutting down hyperrr.

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

func (r *Repository) GetTaxonomyByCode(ctx context.Context, code string) (*Taxonomy, error)

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

func (*Taxonomy) BeforeCreate

func (t *Taxonomy) BeforeCreate(tx *gorm.DB) error

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

Jump to

Keyboard shortcuts

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