treecluster

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

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 (*TreeClusterService) Delete

func (s *TreeClusterService) Delete(ctx context.Context, id int32) error

func (*TreeClusterService) GetAll

func (*TreeClusterService) GetByID

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 (*TreeClusterService) UpdateWateringStatuses

func (s *TreeClusterService) UpdateWateringStatuses(ctx context.Context) error

Jump to

Keyboard shortcuts

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