diff --git a/dtos/autoevent.go b/dtos/autoevent.go index ca3dd090..82c42bc3 100644 --- a/dtos/autoevent.go +++ b/dtos/autoevent.go @@ -1,5 +1,6 @@ // // Copyright (C) 2020-2023 IOTech Ltd +// Copyright (C) 2025 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -10,10 +11,17 @@ import ( ) type AutoEvent struct { - Interval string `json:"interval" yaml:"interval" validate:"required,edgex-dto-duration=1ms"` // min/max can be defined as params, ex. edgex-dto-duration=10ms0x2C24h - OnChange bool `json:"onChange" yaml:"onChange"` - OnChangeThreshold float64 `json:"onChangeThreshold" yaml:"onChangeThreshold" validate:"gte=0"` - SourceName string `json:"sourceName" yaml:"sourceName" validate:"required"` + Interval string `json:"interval" yaml:"interval" validate:"required,edgex-dto-duration=1ms"` // min/max can be defined as params, ex. edgex-dto-duration=10ms0x2C24h + OnChange bool `json:"onChange" yaml:"onChange"` + OnChangeThreshold float64 `json:"onChangeThreshold" yaml:"onChangeThreshold" validate:"gte=0"` + SourceName string `json:"sourceName" yaml:"sourceName" validate:"required"` + Retention Retention `json:"retention" yaml:"retention" validate:"omitempty"` +} + +type Retention struct { + MaxCap int64 `json:"maxCap" yaml:"maxCap"` + MinCap int64 `json:"minCap" yaml:"minCap"` + Duration string `json:"duration" yaml:"duration" validate:"edgex-dto-duration=0s"` } // ToAutoEventModel transforms the AutoEvent DTO to the AutoEvent model @@ -23,6 +31,11 @@ func ToAutoEventModel(a AutoEvent) models.AutoEvent { OnChange: a.OnChange, OnChangeThreshold: a.OnChangeThreshold, SourceName: a.SourceName, + Retention: models.Retention{ + MaxCap: a.Retention.MaxCap, + MinCap: a.Retention.MinCap, + Duration: a.Retention.Duration, + }, } } @@ -42,6 +55,11 @@ func FromAutoEventModelToDTO(a models.AutoEvent) AutoEvent { OnChange: a.OnChange, OnChangeThreshold: a.OnChangeThreshold, SourceName: a.SourceName, + Retention: Retention{ + MaxCap: a.Retention.MaxCap, + MinCap: a.Retention.MinCap, + Duration: a.Retention.Duration, + }, } } diff --git a/models/autoevent.go b/models/autoevent.go index 51a7b98a..61c117fa 100644 --- a/models/autoevent.go +++ b/models/autoevent.go @@ -1,5 +1,6 @@ // // Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2025 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -10,4 +11,11 @@ type AutoEvent struct { OnChange bool OnChangeThreshold float64 SourceName string + Retention Retention +} + +type Retention struct { + MaxCap int64 + MinCap int64 + Duration string }