Documentation
¶
Overview ¶
Package memory provides the business logic layer for observation management.
The Service implements domain-level validation, default value handling, and orchestrates persistence operations through the ObservationRepository interface. This is the primary entry point for all observation-related operations.
Index ¶
- type Service
- func (s *Service) Delete(ctx context.Context, id int64) error
- func (s *Service) Get(ctx context.Context, id int64) (*domain.Observation, error)
- func (s *Service) GetByTopicKey(ctx context.Context, project, topicKey string) (*domain.Observation, error)
- func (s *Service) List(ctx context.Context, filter domain.ObservationFilter) ([]*domain.Observation, error)
- func (s *Service) Save(ctx context.Context, obs *domain.Observation) error
- func (s *Service) Update(ctx context.Context, obs *domain.Observation) error
- func (s *Service) UpsertByTopicKey(ctx context.Context, obs *domain.Observation) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides business logic for observation management. It wraps an ObservationRepository and adds validation, defaults, and domain rules enforcement.
func NewService ¶
func NewService(repo domain.ObservationRepository) *Service
NewService creates a new memory Service with the given repository.
func (*Service) Delete ¶
Delete removes an observation by ID. This performs a soft delete by default.
func (*Service) Get ¶
Get retrieves an observation by its ID. Returns ErrNotFound if the observation doesn't exist.
func (*Service) GetByTopicKey ¶
func (s *Service) GetByTopicKey(ctx context.Context, project, topicKey string) (*domain.Observation, error)
GetByTopicKey retrieves an observation by its topic key within a project. This is used for upsert operations where topic_key enforces uniqueness. Returns ErrNotFound if no matching observation exists.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, filter domain.ObservationFilter) ([]*domain.Observation, error)
List retrieves observations based on filter criteria. An empty filter returns all observations up to the default limit.
func (*Service) Save ¶
Save creates or updates an observation.
Business Rules:
- Title and Content are required (validation error if empty)
- Type defaults to "manual" if empty
- Scope defaults to "project" if empty
- CreatedAt is set to now for new observations
- UpdatedAt is always set to now
func (*Service) Update ¶
Update modifies an existing observation.
Business Rules:
- Title and Content are required (validation error if empty)
- UpdatedAt is always set to now
- CreatedAt is preserved
func (*Service) UpsertByTopicKey ¶
UpsertByTopicKey creates or updates an observation based on its topic key.
Business Rules:
- If an observation with the same topic_key exists in the project, update it
- Otherwise, create a new observation
- Topic key is normalized (lowercase, trimmed)
- All validation rules from Save apply