findingsource

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 (
	// 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

func AllowedSortFields() map[string]string

AllowedSortFields returns the allowed sort fields for finding sources.

func CategoryAllowedSortFields

func CategoryAllowedSortFields() map[string]string

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

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
	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 NewFilter

func NewFilter() Filter

NewFilter creates an empty filter.

func (Filter) WithCategoryCode

func (f Filter) WithCategoryCode(categoryCode string) Filter

WithCategoryCode adds a category code 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) 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.

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

func (f *FindingSource) ID() shared.ID

Getters

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

Jump to

Keyboard shortcuts

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