-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdto.go
119 lines (102 loc) · 2.71 KB
/
dto.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import "time"
const (
MatchMakerSerialColumn = "matchmaker_serial"
UserReferenceColumn = "user_reference"
SerialColumn = "serial"
StatusColumn = "status"
)
type MatchMaker struct {
Serial string `gorm:"uniqueIndex"`
Name string
Description string
Status MatchMakerStatus
StartTime time.Time
EndTime time.Time
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
func (MatchMaker) TableName() string {
return "matchmaker"
}
func (MatchMaker) FromEntity(entity *MatchMakerEntity) *MatchMaker {
if entity == nil {
return nil
}
return &MatchMaker{
Serial: entity.Serial,
Name: entity.Name,
Description: entity.Description,
Status: entity.Status,
StartTime: entity.StartTime,
EndTime: entity.StartTime.Add(entity.Duration * Day),
}
}
func (m *MatchMaker) ToEntity() *MatchMakerEntity {
if m == nil {
return nil
}
return &MatchMakerEntity{
Serial: m.Serial,
Name: m.Name,
Description: m.Description,
StartTime: m.StartTime,
Duration: m.EndTime.Sub(m.StartTime),
Status: m.Status,
}
}
type MatchMakerUser struct {
MatchMakerSerial string `gorm:"column:matchmaker_serial"`
Serial string `gorm:"uniqueIndex"`
UserReference string
Status MatchMakerUserStatus
DeletedAt *time.Time
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
func (MatchMakerUser) TableName() string {
return "matchmaker_user"
}
func (m *MatchMakerUser) FromEntity(entity *MatchMakerUserEntity) *MatchMakerUser {
if entity == nil {
return nil
}
return &MatchMakerUser{
MatchMakerSerial: entity.MatchMakerSerial,
Serial: entity.Serial,
UserReference: entity.UserReference,
Status: entity.Status,
}
}
func (m *MatchMakerUser) ToEntity() *MatchMakerUserEntity {
if m == nil {
return nil
}
return &MatchMakerUserEntity{
MatchMakerSerial: m.MatchMakerSerial,
Serial: m.Serial,
UserReference: m.UserReference,
Status: m.Status,
}
}
type MatchMakerUsers []*MatchMakerUser
func (m MatchMakerUsers) FromEntities(entities MatchMakerUserEntities) MatchMakerUsers {
var matchMakerUsers MatchMakerUsers
for _, entity := range entities {
if entity == nil {
continue
}
matchMakerUsers = append(matchMakerUsers, (&MatchMakerUser{}).FromEntity(entity))
}
return matchMakerUsers
}
func (m MatchMakerUsers) ToEntities() MatchMakerUserEntities {
var entities MatchMakerUserEntities
for _, matchMakerUser := range m {
if matchMakerUser == nil {
continue
}
entities = append(entities, matchMakerUser.ToEntity())
}
return entities
}