dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/interval.go (about) 1 // 2 // Copyright (C) 2021 IOTech Ltd 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 6 package dtos 7 8 import ( 9 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models" 10 ) 11 12 type Interval struct { 13 DBTimestamp `json:",inline"` 14 Id string `json:"id,omitempty" validate:"omitempty,uuid"` 15 Name string `json:"name" validate:"edgex-dto-none-empty-string"` 16 Start string `json:"start,omitempty" validate:"omitempty,edgex-dto-interval-datetime"` 17 End string `json:"end,omitempty" validate:"omitempty,edgex-dto-interval-datetime"` 18 Interval string `json:"interval" validate:"required,edgex-dto-duration"` 19 } 20 21 // NewInterval creates interval DTO with required fields 22 func NewInterval(name, interval string) Interval { 23 return Interval{Name: name, Interval: interval} 24 } 25 26 type UpdateInterval struct { 27 Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"` 28 Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"` 29 Start *string `json:"start" validate:"omitempty,edgex-dto-interval-datetime"` 30 End *string `json:"end" validate:"omitempty,edgex-dto-interval-datetime"` 31 Interval *string `json:"interval" validate:"omitempty,edgex-dto-duration"` 32 } 33 34 // NewUpdateInterval creates updateInterval DTO with required field 35 func NewUpdateInterval(name string) UpdateInterval { 36 return UpdateInterval{Name: &name} 37 } 38 39 // ToIntervalModel transforms the Interval DTO to the Interval Model 40 func ToIntervalModel(dto Interval) models.Interval { 41 var model models.Interval 42 model.Id = dto.Id 43 model.Name = dto.Name 44 model.Start = dto.Start 45 model.End = dto.End 46 model.Interval = dto.Interval 47 return model 48 } 49 50 // FromIntervalModelToDTO transforms the Interval Model to the Interval DTO 51 func FromIntervalModelToDTO(model models.Interval) Interval { 52 var dto Interval 53 dto.DBTimestamp = DBTimestamp(model.DBTimestamp) 54 dto.Id = model.Id 55 dto.Name = model.Name 56 dto.Start = model.Start 57 dto.End = model.End 58 dto.Interval = model.Interval 59 return dto 60 }