Documentation
¶
Index ¶
- Variables
- func AllowedSortFields() map[string]string
- func CategoryAllowedSortFields() map[string]string
- 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) WithCategoryCode(categoryCode string) 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) WithIsSystem(isSystem bool) Filter
- func (f Filter) WithName(name string) Filter
- func (f Filter) WithSearch(search string) Filter
- type FindingSource
- func (f *FindingSource) Activate()
- func (f *FindingSource) CategoryID() *shared.ID
- func (f *FindingSource) Code() string
- func (f *FindingSource) Color() string
- func (f *FindingSource) CreatedAt() time.Time
- func (f *FindingSource) Deactivate()
- func (f *FindingSource) Description() string
- func (f *FindingSource) DisplayOrder() int
- func (f *FindingSource) ID() shared.ID
- func (f *FindingSource) Icon() string
- func (f *FindingSource) IsActive() bool
- func (f *FindingSource) IsSystem() bool
- func (f *FindingSource) Name() string
- func (f *FindingSource) SetCategoryID(categoryID *shared.ID)
- func (f *FindingSource) SetColor(color string)
- func (f *FindingSource) SetDescription(description string)
- func (f *FindingSource) SetDisplayOrder(order int)
- func (f *FindingSource) SetIcon(icon string)
- func (f *FindingSource) UpdatedAt() time.Time
- type FindingSourceWithCategory
- type ListOptions
- type Repository
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFindingSourceNotFound is returned when a finding source is not found. ErrFindingSourceNotFound = errors.New("finding source not found") // ErrFindingSourceCodeExists is returned when a finding source with the same code already exists. ErrFindingSourceCodeExists = errors.New("finding source 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") // ErrCannotDeleteSystemSource is returned when trying to delete a system finding source. ErrCannotDeleteSystemSource = errors.New("cannot delete system finding source") // ErrCannotModifySystemSource is returned when trying to modify certain fields of a system source. ErrCannotModifySystemSource = errors.New("cannot modify system finding source") // ErrCategoryHasFindingSources is returned when trying to delete a category that has finding sources. ErrCategoryHasFindingSources = errors.New("category has associated finding sources") // ErrInvalidFindingSource is returned when a finding source code is not valid. ErrInvalidFindingSource = errors.New("invalid finding source code") )
Functions ¶
func AllowedSortFields ¶
AllowedSortFields returns the allowed sort fields for finding sources.
func CategoryAllowedSortFields ¶
CategoryAllowedSortFields returns the allowed sort fields for categories.
Types ¶
type Category ¶
type Category struct {
// contains filtered or unexported fields
}
Category represents a finding source 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
CategoryCode *string // Filter by category code
Code *string // Filter by code
Name *string // Filter by name (partial match)
IsActive *bool // Filter by active status
IsSystem *bool // Filter by system type
Search *string // Full-text search
Codes []string // Filter by multiple codes
}
Filter defines the filtering options for listing finding sources.
func (Filter) WithCategoryCode ¶
WithCategoryCode adds a category code filter.
func (Filter) WithCategoryID ¶
WithCategoryID adds a category ID filter.
func (Filter) WithIsActive ¶
WithIsActive adds an active status filter.
func (Filter) WithIsSystem ¶
WithIsSystem adds a system type filter.
func (Filter) WithSearch ¶
WithSearch adds a search filter.
type FindingSource ¶
type FindingSource struct {
// contains filtered or unexported fields
}
FindingSource represents a master finding source. Finding sources are system-level configuration, not per-tenant. Created only via DB seed or by system admin.
func NewFindingSource ¶
func NewFindingSource(code, name string) (*FindingSource, error)
NewFindingSource creates a new FindingSource entity.
func ReconstituteFindingSource ¶
func ReconstituteFindingSource( id shared.ID, categoryID *shared.ID, code, name, description string, icon, color string, displayOrder int, isSystem, isActive bool, createdAt, updatedAt time.Time, ) *FindingSource
ReconstituteFindingSource recreates a FindingSource from persistence.
func (*FindingSource) Activate ¶
func (f *FindingSource) Activate()
func (*FindingSource) CategoryID ¶
func (f *FindingSource) CategoryID() *shared.ID
func (*FindingSource) Code ¶
func (f *FindingSource) Code() string
func (*FindingSource) Color ¶
func (f *FindingSource) Color() string
func (*FindingSource) CreatedAt ¶
func (f *FindingSource) CreatedAt() time.Time
func (*FindingSource) Deactivate ¶
func (f *FindingSource) Deactivate()
func (*FindingSource) Description ¶
func (f *FindingSource) Description() string
func (*FindingSource) DisplayOrder ¶
func (f *FindingSource) DisplayOrder() int
func (*FindingSource) Icon ¶
func (f *FindingSource) Icon() string
func (*FindingSource) IsActive ¶
func (f *FindingSource) IsActive() bool
func (*FindingSource) IsSystem ¶
func (f *FindingSource) IsSystem() bool
func (*FindingSource) Name ¶
func (f *FindingSource) Name() string
func (*FindingSource) SetCategoryID ¶
func (f *FindingSource) SetCategoryID(categoryID *shared.ID)
Setters
func (*FindingSource) SetColor ¶
func (f *FindingSource) SetColor(color string)
func (*FindingSource) SetDescription ¶
func (f *FindingSource) SetDescription(description string)
func (*FindingSource) SetDisplayOrder ¶
func (f *FindingSource) SetDisplayOrder(order int)
func (*FindingSource) SetIcon ¶
func (f *FindingSource) SetIcon(icon string)
func (*FindingSource) UpdatedAt ¶
func (f *FindingSource) UpdatedAt() time.Time
type FindingSourceWithCategory ¶
type FindingSourceWithCategory struct {
FindingSource *FindingSource
Category *Category
}
FindingSourceWithCategory represents a finding source with its category loaded.
type ListOptions ¶
type ListOptions struct {
Sort *pagination.SortOption
}
ListOptions contains options for listing finding sources.
func (ListOptions) WithSort ¶
func (o ListOptions) WithSort(sort *pagination.SortOption) ListOptions
WithSort adds sorting options.
type Repository ¶
type Repository interface {
// GetByID retrieves a finding source by its ID.
GetByID(ctx context.Context, id shared.ID) (*FindingSource, error)
// GetByCode retrieves a finding source by its code.
GetByCode(ctx context.Context, code string) (*FindingSource, error)
// List retrieves finding sources with filtering and pagination.
List(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*FindingSource], error)
// ListWithCategory retrieves finding sources with their categories.
ListWithCategory(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*FindingSourceWithCategory], error)
// ListActive retrieves all active finding sources.
ListActive(ctx context.Context) ([]*FindingSource, error)
// ListActiveWithCategory retrieves all active finding sources with their categories.
ListActiveWithCategory(ctx context.Context) ([]*FindingSourceWithCategory, error)
// ListActiveByCategory retrieves active finding sources by category.
ListActiveByCategory(ctx context.Context, categoryID shared.ID) ([]*FindingSource, error)
// ExistsByCode checks if a finding source with the given code exists.
ExistsByCode(ctx context.Context, code string) (bool, error)
// IsValidCode checks if the code is a valid active finding source.
IsValidCode(ctx context.Context, code string) (bool, error)
}
Repository defines the interface for finding source persistence. Finding sources are read-only for regular users (system-level configuration).