assettype

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAssetTypeNotFound is returned when an asset type is not found.
	ErrAssetTypeNotFound = errors.New("asset type not found")

	// ErrAssetTypeCodeExists is returned when an asset type with the same code already exists.
	ErrAssetTypeCodeExists = errors.New("asset type with this code already exists")

	// ErrCategoryNotFound is returned when a category is not found.
	ErrCategoryNotFound = errors.New("category not found")

	// ErrCategoryCodeExists is returned when a category with the same code already exists.
	ErrCategoryCodeExists = errors.New("category with this code already exists")

	// ErrCannotDeleteSystemType is returned when trying to delete a system asset type.
	ErrCannotDeleteSystemType = errors.New("cannot delete system asset type")

	// ErrCannotModifySystemType is returned when trying to modify certain fields of a system type.
	ErrCannotModifySystemType = errors.New("cannot modify system asset type")

	// ErrCategoryHasAssetTypes is returned when trying to delete a category that has asset types.
	ErrCategoryHasAssetTypes = errors.New("category has associated asset types")
)

Functions

func AllowedSortFields

func AllowedSortFields() map[string]string

AllowedSortFields returns the allowed sort fields for asset types.

func CategoryAllowedSortFields

func CategoryAllowedSortFields() map[string]string

CategoryAllowedSortFields returns the allowed sort fields for categories.

Types

type AssetType

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

AssetType represents a master asset type. Asset types are system-level configuration, not per-tenant. Created only via DB seed or by system admin.

func NewAssetType

func NewAssetType(code, name string) (*AssetType, error)

NewAssetType creates a new AssetType entity.

func ReconstituteAssetType

func ReconstituteAssetType(
	id shared.ID,
	categoryID *shared.ID,
	code, name, description string,
	icon, color string,
	displayOrder int,
	patternRegex, patternPlaceholder, patternExample string,
	supportsWildcard, supportsCIDR bool,
	isDiscoverable, isScannable bool,
	isSystem, isActive bool,
	createdAt, updatedAt time.Time,
) *AssetType

ReconstituteAssetType recreates an AssetType from persistence.

func (*AssetType) Activate

func (a *AssetType) Activate()

func (*AssetType) CategoryID

func (a *AssetType) CategoryID() *shared.ID

func (*AssetType) Code

func (a *AssetType) Code() string

func (*AssetType) Color

func (a *AssetType) Color() string

func (*AssetType) CreatedAt

func (a *AssetType) CreatedAt() time.Time

func (*AssetType) Deactivate

func (a *AssetType) Deactivate()

func (*AssetType) Description

func (a *AssetType) Description() string

func (*AssetType) DisplayOrder

func (a *AssetType) DisplayOrder() int

func (*AssetType) ID

func (a *AssetType) ID() shared.ID

Getters

func (*AssetType) Icon

func (a *AssetType) Icon() string

func (*AssetType) IsActive

func (a *AssetType) IsActive() bool

func (*AssetType) IsDiscoverable

func (a *AssetType) IsDiscoverable() bool

func (*AssetType) IsScannable

func (a *AssetType) IsScannable() bool

func (*AssetType) IsSystem

func (a *AssetType) IsSystem() bool

func (*AssetType) Name

func (a *AssetType) Name() string

func (*AssetType) PatternExample

func (a *AssetType) PatternExample() string

func (*AssetType) PatternPlaceholder

func (a *AssetType) PatternPlaceholder() string

func (*AssetType) PatternRegex

func (a *AssetType) PatternRegex() string

func (*AssetType) SetCategoryID

func (a *AssetType) SetCategoryID(categoryID *shared.ID)

Setters

func (*AssetType) SetColor

func (a *AssetType) SetColor(color string)

func (*AssetType) SetDescription

func (a *AssetType) SetDescription(description string)

func (*AssetType) SetDisplayOrder

func (a *AssetType) SetDisplayOrder(order int)

func (*AssetType) SetIcon

func (a *AssetType) SetIcon(icon string)

func (*AssetType) SetIsDiscoverable

func (a *AssetType) SetIsDiscoverable(discoverable bool)

func (*AssetType) SetIsScannable

func (a *AssetType) SetIsScannable(scannable bool)

func (*AssetType) SetPatternExample

func (a *AssetType) SetPatternExample(example string)

func (*AssetType) SetPatternPlaceholder

func (a *AssetType) SetPatternPlaceholder(placeholder string)

func (*AssetType) SetPatternRegex

func (a *AssetType) SetPatternRegex(regex string)

func (*AssetType) SetSupportsCIDR

func (a *AssetType) SetSupportsCIDR(supports bool)

func (*AssetType) SetSupportsWildcard

func (a *AssetType) SetSupportsWildcard(supports bool)

func (*AssetType) SupportsCIDR

func (a *AssetType) SupportsCIDR() bool

func (*AssetType) SupportsWildcard

func (a *AssetType) SupportsWildcard() bool

func (*AssetType) UpdatedAt

func (a *AssetType) UpdatedAt() time.Time

type AssetTypeWithCategory

type AssetTypeWithCategory struct {
	AssetType *AssetType
	Category  *Category
}

AssetTypeWithCategory represents an asset type with its category loaded.

type Category

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

Category represents an asset type category.

func NewCategory

func NewCategory(code, name string) (*Category, error)

NewCategory creates a new Category entity.

func ReconstituteCategory

func ReconstituteCategory(
	id shared.ID,
	code, name, description, icon string,
	displayOrder int,
	isActive bool,
	createdAt, updatedAt time.Time,
) *Category

ReconstituteCategory recreates a Category from persistence.

func (*Category) Activate

func (c *Category) Activate()

func (*Category) Code

func (c *Category) Code() string

func (*Category) CreatedAt

func (c *Category) CreatedAt() time.Time

func (*Category) Deactivate

func (c *Category) Deactivate()

func (*Category) Description

func (c *Category) Description() string

func (*Category) DisplayOrder

func (c *Category) DisplayOrder() int

func (*Category) ID

func (c *Category) ID() shared.ID

Getters

func (*Category) Icon

func (c *Category) Icon() string

func (*Category) IsActive

func (c *Category) IsActive() bool

func (*Category) Name

func (c *Category) Name() string

func (*Category) SetDescription

func (c *Category) SetDescription(description string)

Setters

func (*Category) SetDisplayOrder

func (c *Category) SetDisplayOrder(order int)

func (*Category) SetIcon

func (c *Category) SetIcon(icon string)

func (*Category) UpdatedAt

func (c *Category) UpdatedAt() time.Time

type CategoryFilter

type CategoryFilter struct {
	Code     *string // Filter by code
	Name     *string // Filter by name (partial match)
	IsActive *bool   // Filter by active status
	Search   *string // Full-text search
}

CategoryFilter defines the filtering options for listing categories.

func NewCategoryFilter

func NewCategoryFilter() CategoryFilter

NewCategoryFilter creates an empty category filter.

func (CategoryFilter) WithCode

func (f CategoryFilter) WithCode(code string) CategoryFilter

WithCode adds a code filter.

func (CategoryFilter) WithIsActive

func (f CategoryFilter) WithIsActive(isActive bool) CategoryFilter

WithIsActive adds an active status filter.

func (CategoryFilter) WithName

func (f CategoryFilter) WithName(name string) CategoryFilter

WithName adds a name filter.

func (CategoryFilter) WithSearch

func (f CategoryFilter) WithSearch(search string) CategoryFilter

WithSearch adds a search filter.

type CategoryRepository

type CategoryRepository interface {
	// Create persists a new category.
	Create(ctx context.Context, category *Category) error

	// GetByID retrieves a category by its ID.
	GetByID(ctx context.Context, id shared.ID) (*Category, error)

	// GetByCode retrieves a category by its code.
	GetByCode(ctx context.Context, code string) (*Category, error)

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

	// Delete removes a category by its ID.
	Delete(ctx context.Context, id shared.ID) error

	// List retrieves categories with pagination.
	List(ctx context.Context, filter CategoryFilter, page pagination.Pagination) (pagination.Result[*Category], error)

	// ListActive retrieves all active categories.
	ListActive(ctx context.Context) ([]*Category, error)
}

CategoryRepository defines the interface for category persistence.

type Filter

type Filter struct {
	CategoryID       *string  // Filter by category ID
	Code             *string  // Filter by code
	Name             *string  // Filter by name (partial match)
	IsActive         *bool    // Filter by active status
	IsSystem         *bool    // Filter by system type
	IsDiscoverable   *bool    // Filter by discoverable
	IsScannable      *bool    // Filter by scannable
	SupportsWildcard *bool    // Filter by wildcard support
	SupportsCIDR     *bool    // Filter by CIDR support
	Search           *string  // Full-text search
	Codes            []string // Filter by multiple codes
}

Filter defines the filtering options for listing asset types.

func NewFilter

func NewFilter() Filter

NewFilter creates an empty filter.

func (Filter) WithCategoryID

func (f Filter) WithCategoryID(categoryID string) Filter

WithCategoryID adds a category ID filter.

func (Filter) WithCode

func (f Filter) WithCode(code string) Filter

WithCode adds a code filter.

func (Filter) WithCodes

func (f Filter) WithCodes(codes ...string) Filter

WithCodes adds multiple codes filter.

func (Filter) WithIsActive

func (f Filter) WithIsActive(isActive bool) Filter

WithIsActive adds an active status filter.

func (Filter) WithIsDiscoverable

func (f Filter) WithIsDiscoverable(discoverable bool) Filter

WithIsDiscoverable adds a discoverable filter.

func (Filter) WithIsScannable

func (f Filter) WithIsScannable(scannable bool) Filter

WithIsScannable adds a scannable filter.

func (Filter) WithIsSystem

func (f Filter) WithIsSystem(isSystem bool) Filter

WithIsSystem adds a system type filter.

func (Filter) WithName

func (f Filter) WithName(name string) Filter

WithName adds a name filter.

func (Filter) WithSearch

func (f Filter) WithSearch(search string) Filter

WithSearch adds a search filter.

func (Filter) WithSupportsCIDR

func (f Filter) WithSupportsCIDR(supports bool) Filter

WithSupportsCIDR adds a CIDR support filter.

func (Filter) WithSupportsWildcard

func (f Filter) WithSupportsWildcard(supports bool) Filter

WithSupportsWildcard adds a wildcard support filter.

type ListOptions

type ListOptions struct {
	Sort *pagination.SortOption
}

ListOptions contains options for listing asset types.

func NewListOptions

func NewListOptions() ListOptions

NewListOptions creates empty list options.

func (ListOptions) WithSort

func (o ListOptions) WithSort(sort *pagination.SortOption) ListOptions

WithSort adds sorting options.

type Repository

type Repository interface {
	// GetByID retrieves an asset type by its ID.
	GetByID(ctx context.Context, id shared.ID) (*AssetType, error)

	// GetByCode retrieves an asset type by its code.
	GetByCode(ctx context.Context, code string) (*AssetType, error)

	// List retrieves asset types with filtering and pagination.
	List(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*AssetType], error)

	// ListWithCategory retrieves asset types with their categories.
	ListWithCategory(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*AssetTypeWithCategory], error)

	// ListActive retrieves all active asset types.
	ListActive(ctx context.Context) ([]*AssetType, error)

	// ListActiveByCategory retrieves active asset types by category.
	ListActiveByCategory(ctx context.Context, categoryID shared.ID) ([]*AssetType, error)

	// ExistsByCode checks if an asset type with the given code exists.
	ExistsByCode(ctx context.Context, code string) (bool, error)
}

Repository defines the interface for asset type persistence. Asset types are read-only for regular users (system-level configuration).

Jump to

Keyboard shortcuts

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