-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardSkill.go
140 lines (119 loc) · 3.61 KB
/
cardSkill.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package skillgo
import "reflect"
// BasicCardType is BasicCard template
type BasicCardType struct {
BasicCard struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Thumbnail ThumbnailType `json:"thumbnail"`
// Profile 미지원
Profile struct {
ImageURL string `json:"imageUrl"`
Nickname string `json:"nickname"`
} `json:"profile,omitempty"`
// Social 미지원
Social struct {
Like int `json:"like"`
Comment int `json:"comment"`
Share int `json:"share"`
} `json:"social,omitempty"`
Buttons []ButtonType `json:"buttons,omitempty"`
} `json:"basicCard"`
}
// BasicCard creates BasicCard SkillResponse
func BasicCard(title string, description string, thumbnail ThumbnailType, buttons []ButtonType) BasicCardType {
resposne := BasicCardType{}
resposne.BasicCard.Thumbnail = thumbnail
if title != "" {
resposne.BasicCard.Title = title
}
if description != "" {
resposne.BasicCard.Description = description
}
if len(buttons) != 0 {
resposne.BasicCard.Buttons = buttons
}
return resposne
}
// CommerceCardType is CommerceCard template
type CommerceCardType struct {
CommerceCard struct {
Description string `json:"description"`
Price int `json:"price"`
Currency string `json:"currency"`
Discount int `json:"discount,omitempty"`
DiscountRate int `json:"discountRate,omitempty"`
DiscountedPrice int `json:"dicountedPrice,omitempty"`
Thumbnails []ThumbnailType `json:"thumbnails"`
Profile ProfileType `json:"profile,omitempty"`
Buttons []ButtonType `json:"buttons"`
} `json:"commerceCard"`
}
// CommerceCard creates CommerceCard SkillResponse
func CommerceCard(
description string,
price int,
currency string,
discount int,
discountRate int,
discountedPrice int,
thumbnails []ThumbnailType,
profile ProfileType,
buttons []ButtonType,
) CommerceCardType {
response := CommerceCardType{}
response.CommerceCard.Description = description
response.CommerceCard.Price = price
response.CommerceCard.Currency = currency
if discount != 0 {
response.CommerceCard.Discount = discount
}
if discountRate != 0 {
response.CommerceCard.DiscountRate = discountRate
}
if discountedPrice != 0 {
response.CommerceCard.DiscountedPrice = discountedPrice
}
response.CommerceCard.Buttons = buttons
return response
}
// ListCardType is ListCard template
type ListCardType struct {
ListCard struct {
Header ListItemType `json:"header"`
Items []ListItemType `json:"items"`
Buttons []ButtonType `json:"buttons,omitempty"`
} `json:"listCard"`
}
// ListItemType is ListItem template
type ListItemType struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
ImageURL string `json:"imageUrl,omitempty"`
Link LinkType `json:"link,omitempty"`
}
// ListCard creates ListCard SkillResponse
func ListCard(header ListItemType, items []ListItemType, buttons []ButtonType) ListCardType {
response := ListCardType{}
response.ListCard.Header = header
response.ListCard.Items = items
if len(buttons) != 0 {
response.ListCard.Buttons = buttons
}
return response
}
// ListItem creates ListItem for ListCard
func ListItem(title string, description string, imageURL string, link LinkType) ListItemType {
response := ListItemType{}
response.Title = title
if description != "" {
response.Description = description
}
if imageURL != "" {
response.ImageURL = imageURL
}
if !reflect.DeepEqual(link, LinkType{}) {
response.Link = link
}
return response
}