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