toolcategory

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: GPL-3.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package toolcategory defines the ToolCategory domain entity. Tool categories can be platform-wide (builtin) or tenant-specific (custom).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	TenantID  *shared.ID // Include tenant custom categories
	IsBuiltin *bool      // Filter by builtin status
	Search    string     // Search by name or display name
}

Filter defines filter options for listing categories.

type Repository

type Repository interface {
	// Create creates a new tool category.
	Create(ctx context.Context, category *ToolCategory) error

	// GetByID returns a category by ID.
	GetByID(ctx context.Context, id shared.ID) (*ToolCategory, error)

	// GetByName returns a category by name within a scope (tenant or platform).
	// If tenantID is nil, it looks for platform category.
	GetByName(ctx context.Context, tenantID *shared.ID, name string) (*ToolCategory, error)

	// List returns categories matching the filter with pagination.
	// Always includes platform (builtin) categories.
	// If filter.TenantID is set, also includes that tenant's custom categories.
	List(ctx context.Context, filter Filter, page pagination.Pagination) (pagination.Result[*ToolCategory], error)

	// ListAll returns all categories for a tenant context (platform + tenant custom).
	// This is a simpler method without pagination for dropdowns/selects.
	ListAll(ctx context.Context, tenantID *shared.ID) ([]*ToolCategory, error)

	// Update updates an existing category.
	Update(ctx context.Context, category *ToolCategory) error

	// Delete deletes a category by ID.
	// Only tenant custom categories can be deleted.
	Delete(ctx context.Context, id shared.ID) error

	// ExistsByName checks if a category with the given name exists in the scope.
	ExistsByName(ctx context.Context, tenantID *shared.ID, name string) (bool, error)

	// CountByTenant returns the number of custom categories for a tenant.
	CountByTenant(ctx context.Context, tenantID shared.ID) (int64, error)
}

Repository defines the interface for tool category persistence.

type ToolCategory

type ToolCategory struct {
	ID          shared.ID
	TenantID    *shared.ID // nil = platform category, UUID = tenant custom category
	Name        string     // Unique slug: 'sast', 'my-custom-cat'
	DisplayName string     // Display: 'SAST', 'My Custom Category'
	Description string

	// UI customization
	Icon  string // Lucide icon name
	Color string // Badge color

	// Status
	IsBuiltin bool
	SortOrder int

	// Audit
	CreatedBy *shared.ID
	CreatedAt time.Time
	UpdatedAt time.Time
}

ToolCategory represents a tool category. Platform categories (TenantID = nil, IsBuiltin = true) are available to all tenants. Tenant custom categories (TenantID = UUID, IsBuiltin = false) are private to that tenant.

func NewPlatformCategory

func NewPlatformCategory(
	name string,
	displayName string,
	description string,
	icon string,
	color string,
	sortOrder int,
) (*ToolCategory, error)

NewPlatformCategory creates a new platform (builtin) category.

func NewTenantCategory

func NewTenantCategory(
	tenantID shared.ID,
	createdBy shared.ID,
	name string,
	displayName string,
	description string,
	icon string,
	color string,
) (*ToolCategory, error)

NewTenantCategory creates a new tenant-specific (custom) category.

func (*ToolCategory) CanBeModifiedByTenant

func (tc *ToolCategory) CanBeModifiedByTenant(tenantID shared.ID) bool

CanBeModifiedByTenant checks if a tenant can modify this category. Only tenant's own custom categories can be modified.

func (*ToolCategory) IsPlatformCategory

func (tc *ToolCategory) IsPlatformCategory() bool

IsPlatformCategory returns true if this is a platform (builtin) category.

func (*ToolCategory) IsTenantCategory

func (tc *ToolCategory) IsTenantCategory() bool

IsTenantCategory returns true if this is a tenant custom category.

func (*ToolCategory) Update

func (tc *ToolCategory) Update(
	displayName string,
	description string,
	icon string,
	color string,
) error

Update updates the category fields.

func (*ToolCategory) Validate

func (tc *ToolCategory) Validate() error

Validate validates the category data.

Jump to

Keyboard shortcuts

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