Documentation
¶
Index ¶
- func NewTreeClusterService(treeClusterRepo storage.TreeClusterRepository, treeRepo storage.TreeRepository, ...) service.TreeClusterService
- type TreeClusterService
- func (s *TreeClusterService) Create(ctx context.Context, createTc *domain.TreeClusterCreate) (*domain.TreeCluster, error)
- func (s *TreeClusterService) Delete(ctx context.Context, id int32) error
- func (s *TreeClusterService) GetAll(ctx context.Context, filter domain.TreeClusterQuery) ([]*domain.TreeCluster, int64, error)
- func (s *TreeClusterService) GetByID(ctx context.Context, id int32) (*domain.TreeCluster, error)
- func (s *TreeClusterService) HandleCreateTree(ctx context.Context, event *entities.EventCreateTree) error
- func (s *TreeClusterService) HandleDeleteTree(ctx context.Context, event *entities.EventDeleteTree) error
- func (s *TreeClusterService) HandleNewSensorData(ctx context.Context, event *entities.EventNewSensorData) error
- func (s *TreeClusterService) HandleUpdateTree(ctx context.Context, event *entities.EventUpdateTree) error
- func (s *TreeClusterService) HandleUpdateWateringPlan(ctx context.Context, event *entities.EventUpdateWateringPlan) error
- func (s *TreeClusterService) Ready() bool
- func (s *TreeClusterService) Update(ctx context.Context, id int32, tcUpdate *domain.TreeClusterUpdate) (*domain.TreeCluster, error)
- func (s *TreeClusterService) UpdateWateringStatuses(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTreeClusterService ¶
func NewTreeClusterService( treeClusterRepo storage.TreeClusterRepository, treeRepo storage.TreeRepository, regionRepo storage.RegionRepository, eventManager *worker.EventManager, ) service.TreeClusterService
Types ¶
type TreeClusterService ¶
type TreeClusterService struct {
// contains filtered or unexported fields
}
func (*TreeClusterService) Create ¶
func (s *TreeClusterService) Create(ctx context.Context, createTc *domain.TreeClusterCreate) (*domain.TreeCluster, error)
func (*TreeClusterService) Delete ¶
func (s *TreeClusterService) Delete(ctx context.Context, id int32) error
func (*TreeClusterService) GetAll ¶
func (s *TreeClusterService) GetAll(ctx context.Context, filter domain.TreeClusterQuery) ([]*domain.TreeCluster, int64, error)
func (*TreeClusterService) GetByID ¶
func (s *TreeClusterService) GetByID(ctx context.Context, id int32) (*domain.TreeCluster, error)
func (*TreeClusterService) HandleCreateTree ¶
func (s *TreeClusterService) HandleCreateTree(ctx context.Context, event *entities.EventCreateTree) error
HandleCreateTree processes a tree creation event and updates the associated tree cluster if necessary.
If the sensor was previously linked to a different tree with a tree cluster, the previous cluster's watering status is recalculated. If the new tree has a tree cluster, an update for that cluster is triggered.
Parameters:
- ctx: The request context, enabling logging and tracing.
- event: Contains details about the created tree, including its previous and new state.
Returns:
- error: An error if updating the previous tree cluster fails; otherwise, nil.
func (*TreeClusterService) HandleDeleteTree ¶
func (s *TreeClusterService) HandleDeleteTree(ctx context.Context, event *entities.EventDeleteTree) error
HandleDeleteTree processes a tree deletion event and updates the affected tree cluster if necessary.
If the deleted tree belonged to a tree cluster, the cluster's watering status is recalculated.
Parameters:
- ctx: The request context, enabling logging and tracing.
- event: Contains details about the deleted tree, including its previous state.
Returns:
- error: An error if updating the tree cluster fails; otherwise, nil.
func (*TreeClusterService) HandleNewSensorData ¶
func (s *TreeClusterService) HandleNewSensorData(ctx context.Context, event *entities.EventNewSensorData) error
HandleNewSensorData processes new sensor data and updates the watering status of a tree cluster if necessary.
The function retrieves the tree associated with the given sensor ID and determines whether it belongs to a tree cluster. If the tree has a linked cluster, the watering status of the entire cluster is calculated based on the latest sensor data. If the calculated watering status differs from the current one, the tree cluster is updated accordingly, and an update event is published.
Parameters:
- ctx: The request context, enabling logging and tracing.
- event: Contains the new sensor data, including the sensor ID and measured watermarks.
Returns:
- error: Always returns nil, as errors during tree or cluster retrieval are logged but do not interrupt execution.
func (*TreeClusterService) HandleUpdateTree ¶
func (s *TreeClusterService) HandleUpdateTree(ctx context.Context, event *entities.EventUpdateTree) error
HandleUpdateTree processes a tree update event and updates the affected tree clusters if necessary.
If the tree's sensor was previously linked to a different tree, the old cluster's watering status is updated. If the tree has moved to a different cluster, both the old and new clusters are updated.
Parameters:
- ctx: The request context, enabling logging and tracing.
- event: Contains details about the tree before and after the update.
Returns:
- error: An error if updating any of the affected tree clusters fails; otherwise, nil.
func (*TreeClusterService) HandleUpdateWateringPlan ¶
func (s *TreeClusterService) HandleUpdateWateringPlan(ctx context.Context, event *entities.EventUpdateWateringPlan) error
HandleUpdateWateringPlan processes an update event for a watering plan and updates tree clusters if necessary.
The function only triggers updates if the watering plan status has changed to "finished," the date remains the same, and the linked tree clusters have not changed in number. If these conditions are met, all affected tree clusters will have their watering status updated. For each tree cluster in the watering plan as well as the trees to this tree cluster, the watering status is set to "just watered," and the last watered date is updated. An update event is then published.
Parameters:
- ctx: The request context, enabling logging and tracing.
- event: Contains details about the updated watering plan, including its previous and new state.
Returns:
- error: An error if updating the previous tree cluster fails; otherwise, nil.
func (*TreeClusterService) Ready ¶
func (s *TreeClusterService) Ready() bool
func (*TreeClusterService) Update ¶
func (s *TreeClusterService) Update(ctx context.Context, id int32, tcUpdate *domain.TreeClusterUpdate) (*domain.TreeCluster, error)
func (*TreeClusterService) UpdateWateringStatuses ¶
func (s *TreeClusterService) UpdateWateringStatuses(ctx context.Context) error