-
Notifications
You must be signed in to change notification settings - Fork 12
/
base.go
50 lines (45 loc) · 1.64 KB
/
base.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
package entity
import (
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
"time"
)
type BaseData struct {
Skip bool `json:"skip,omitempty"`
SkipReason string `json:"skipReason,omitempty"`
Id string `json:"id,omitempty"`
ExternalId string `json:"externalId,omitempty"`
ExternalIdSecond string `json:"externalIdSecond,omitempty"`
ExternalSystem string `json:"externalSystem,omitempty"`
ExternalUrl string `json:"externalUrl,omitempty"`
ExternalSourceEntity string `json:"externalSourceEntity,omitempty"`
CreatedAtStr string `json:"createdAt,omitempty"`
UpdatedAtStr string `json:"updatedAt,omitempty"`
CreatedAt *time.Time `json:"createdAtTime,omitempty"`
UpdatedAt *time.Time `json:"updatedAtTime,omitempty"`
SyncId string `json:"syncId,omitempty"`
AppSource string `json:"appSource,omitempty"`
}
func (b *BaseData) SetCreatedAt() {
if b.CreatedAtStr != "" && b.CreatedAt == nil {
b.CreatedAt, _ = utils.UnmarshalDateTime(b.CreatedAtStr)
}
}
func (b *BaseData) SetUpdatedAt() {
if b.UpdatedAtStr != "" && b.UpdatedAt == nil {
b.UpdatedAt, _ = utils.UnmarshalDateTime(b.UpdatedAtStr)
}
}
func (b *BaseData) SetTimes() {
b.SetCreatedAt()
b.SetUpdatedAt()
if b.CreatedAt != nil {
b.CreatedAt = utils.TimePtr((*b.CreatedAt).UTC())
} else {
b.CreatedAt = utils.TimePtr(utils.Now())
}
if b.UpdatedAt != nil {
b.UpdatedAt = utils.TimePtr((*b.UpdatedAt).UTC())
} else {
b.UpdatedAt = utils.TimePtr(utils.Now())
}
}