Documentation
¶
Index ¶
- Variables
- func AllowedSortFields() map[string]string
- func CategoryAllowedSortFields() map[string]string
- type AssetType
- func (a *AssetType) Activate()
- func (a *AssetType) CategoryID() *shared.ID
- func (a *AssetType) Code() string
- func (a *AssetType) Color() string
- func (a *AssetType) CreatedAt() time.Time
- func (a *AssetType) Deactivate()
- func (a *AssetType) Description() string
- func (a *AssetType) DisplayOrder() int
- func (a *AssetType) ID() shared.ID
- func (a *AssetType) Icon() string
- func (a *AssetType) IsActive() bool
- func (a *AssetType) IsDiscoverable() bool
- func (a *AssetType) IsScannable() bool
- func (a *AssetType) IsSystem() bool
- func (a *AssetType) Name() string
- func (a *AssetType) PatternExample() string
- func (a *AssetType) PatternPlaceholder() string
- func (a *AssetType) PatternRegex() string
- func (a *AssetType) SetCategoryID(categoryID *shared.ID)
- func (a *AssetType) SetColor(color string)
- func (a *AssetType) SetDescription(description string)
- func (a *AssetType) SetDisplayOrder(order int)
- func (a *AssetType) SetIcon(icon string)
- func (a *AssetType) SetIsDiscoverable(discoverable bool)
- func (a *AssetType) SetIsScannable(scannable bool)
- func (a *AssetType) SetPatternExample(example string)
- func (a *AssetType) SetPatternPlaceholder(placeholder string)
- func (a *AssetType) SetPatternRegex(regex string)
- func (a *AssetType) SetSupportsCIDR(supports bool)
- func (a *AssetType) SetSupportsWildcard(supports bool)
- func (a *AssetType) SupportsCIDR() bool
- func (a *AssetType) SupportsWildcard() bool
- func (a *AssetType) UpdatedAt() time.Time
- type AssetTypeWithCategory
- type Category
- func (c *Category) Activate()
- func (c *Category) Code() string
- func (c *Category) CreatedAt() time.Time
- func (c *Category) Deactivate()
- func (c *Category) Description() string
- func (c *Category) DisplayOrder() int
- func (c *Category) ID() shared.ID
- func (c *Category) Icon() string
- func (c *Category) IsActive() bool
- func (c *Category) Name() string
- func (c *Category) SetDescription(description string)
- func (c *Category) SetDisplayOrder(order int)
- func (c *Category) SetIcon(icon string)
- func (c *Category) UpdatedAt() time.Time
- type CategoryFilter
- type CategoryRepository
- type Filter
- func (f Filter) WithCategoryID(categoryID string) Filter
- func (f Filter) WithCode(code string) Filter
- func (f Filter) WithCodes(codes ...string) Filter
- func (f Filter) WithIsActive(isActive bool) Filter
- func (f Filter) WithIsDiscoverable(discoverable bool) Filter
- func (f Filter) WithIsScannable(scannable bool) Filter
- func (f Filter) WithIsSystem(isSystem bool) Filter
- func (f Filter) WithName(name string) Filter
- func (f Filter) WithSearch(search string) Filter
- func (f Filter) WithSupportsCIDR(supports bool) Filter
- func (f Filter) WithSupportsWildcard(supports bool) Filter
- type ListOptions
- type Repository
Constants ¶
This section is empty.
Variables ¶
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 ¶
AllowedSortFields returns the allowed sort fields for asset types.
func CategoryAllowedSortFields ¶
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 ¶
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) CategoryID ¶
func (*AssetType) Deactivate ¶
func (a *AssetType) Deactivate()
func (*AssetType) Description ¶
func (*AssetType) DisplayOrder ¶
func (*AssetType) IsDiscoverable ¶
func (*AssetType) IsScannable ¶
func (*AssetType) PatternExample ¶
func (*AssetType) PatternPlaceholder ¶
func (*AssetType) PatternRegex ¶
func (*AssetType) SetDescription ¶
func (*AssetType) SetDisplayOrder ¶
func (*AssetType) SetIsDiscoverable ¶
func (*AssetType) SetIsScannable ¶
func (*AssetType) SetPatternExample ¶
func (*AssetType) SetPatternPlaceholder ¶
func (*AssetType) SetPatternRegex ¶
func (*AssetType) SetSupportsCIDR ¶
func (*AssetType) SetSupportsWildcard ¶
func (*AssetType) SupportsCIDR ¶
func (*AssetType) SupportsWildcard ¶
type AssetTypeWithCategory ¶
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 ¶
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) Deactivate ¶
func (c *Category) Deactivate()
func (*Category) Description ¶
func (*Category) DisplayOrder ¶
func (*Category) SetDisplayOrder ¶
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 (Filter) WithCategoryID ¶
WithCategoryID adds a category ID filter.
func (Filter) WithIsActive ¶
WithIsActive adds an active status filter.
func (Filter) WithIsDiscoverable ¶
WithIsDiscoverable adds a discoverable filter.
func (Filter) WithIsScannable ¶
WithIsScannable adds a scannable filter.
func (Filter) WithIsSystem ¶
WithIsSystem adds a system type filter.
func (Filter) WithSearch ¶
WithSearch adds a search filter.
func (Filter) WithSupportsCIDR ¶
WithSupportsCIDR adds a CIDR support filter.
func (Filter) WithSupportsWildcard ¶
WithSupportsWildcard adds a wildcard support filter.
type ListOptions ¶
type ListOptions struct {
Sort *pagination.SortOption
}
ListOptions contains options for listing asset types.
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).