forked from kyma-incubator/compass
/
dto.go
102 lines (88 loc) · 1.84 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
package dto
import (
"database/sql"
"github.com/kyma-incubator/compass/docs/investigations/storage/sql-toolbox/libs/beego/internal/model"
)
type ApplicationDTO struct {
ID string `orm:"pk;column(id)"` // TODO really???
Tenant string
Name string
Description string
Labels sql.NullString // JSON
}
func (app *ApplicationDTO) TableName() string {
return "applications"
}
type APIDTO struct {
ID string `orm:"pk"`
AppID string
TargetURL string
}
func (a *APIDTO) TableName() string {
return "apis"
}
type DocumentDTO struct {
ID string `orm:"pk"`
AppID string
Title string
Format string
Data string
}
func (d *DocumentDTO) TableName() string {
return "documents"
}
func (d *DocumentDTO) ToModel() model.Document {
return model.Document{
ID: d.ID,
Data: d.Data,
Format: d.Format,
Title: d.Title,
}
}
func DocumentFromModel(appID string, in model.Document) *DocumentDTO {
return &DocumentDTO{
AppID: appID,
Data: in.Data,
Title: in.Title,
ID: in.ID,
Format: in.Format,
}
}
func (a *APIDTO) ToModel() model.API {
return model.API{
ID: a.ID,
TargetURL: a.TargetURL,
}
}
func APIFromModel(appID string, in model.API) *APIDTO {
return &APIDTO{
ID: in.ID,
TargetURL: in.TargetURL,
AppID: appID,
}
}
func AppFromModel(in model.Application) *ApplicationDTO {
var l sql.NullString
if in.Labels == "" {
l.Valid = false
} else {
l.Valid = true
l.String = in.Labels
}
return &ApplicationDTO{
ID: in.ID,
Labels: l,
Name: in.Name,
Description: in.Description,
Tenant: in.Tenant,
}
}
func (app *ApplicationDTO) ToModel() model.Application {
return model.Application{
ID: app.ID,
Tenant: app.Tenant,
Name: app.Name,
Labels: app.Labels.String,
Description: app.Description,
}
}