Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 5fda0be

Browse files
Merge pull request #54 from ketion-so/fix-title
Change property to object
2 parents e91b2e4 + fabf770 commit 5fda0be

File tree

6 files changed

+60
-34
lines changed

6 files changed

+60
-34
lines changed

notion/database_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestDatabasesService_Get(t *testing.T) {
157157
Object: "database",
158158
CreatedTime: "2020-03-17T19:10:04.968Z",
159159
LastEditedTime: "2020-03-17T21:49:37.913Z",
160-
Title: []RichText{
160+
Title: []TextObject{
161161
{
162162
PlainText: "Grocery List",
163163
Annotations: &Annotations{Color: DefaultColor},

notion/databases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Database struct {
2727
ID string `json:"id" mapstructure:"id"`
2828
CreatedTime string `json:"created_time" mapstructure:"created_time"`
2929
LastEditedTime string `json:"last_edited_time" mapstructure:"last_edited_time"`
30-
Title []RichText `json:"title" mapstructure:"title"`
30+
Title []TextObject `json:"title" mapstructure:"title"`
3131
Properties map[string]Property `json:"properties" mapstructure:"properties"`
3232
}
3333

@@ -42,7 +42,7 @@ type database struct {
4242
ID string `json:"id" mapstructure:"id"`
4343
CreatedTime string `json:"created_time" mapstructure:"created_time"`
4444
LastEditedTime string `json:"last_edited_time" mapstructure:"last_edited_time"`
45-
Title []RichText `json:"title" mapstructure:"title"`
45+
Title []TextObject `json:"title" mapstructure:"title"`
4646
Properties map[string]interface{} `json:"properties" mapstructure:"properties"`
4747
}
4848

notion/pages_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func getPageJSON() string {
8787
}
8888
]
8989
}
90-
9190
}
9291
}`
9392
}
@@ -323,7 +322,7 @@ func TestPagesService_UpdateProperties(t *testing.T) {
323322
},
324323
Properties: map[string]Property{
325324
"In stock": &CheckboxProperty{Type: "checkbox", ID: "{>U;", Checkbox: true},
326-
"Name": &PageTitleProperty{Type: "title", ID: "title", Title: []RichText{
325+
"Name": &PageTitleProperty{Type: "title", ID: "title", Title: []TextObject{
327326
{
328327
PlainText: "Avocado",
329328
Annotations: &Annotations{Color: "default"},

notion/property.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type Property interface {
1313
}
1414

1515
// PageTitleProperty object represents Notion title Property.
16-
//go:generate gomodifytags -file $GOFILE -struct TitleProperty -clear-tags -w
17-
//go:generate gomodifytags --file $GOFILE --struct TitleProperty -add-tags json,mapstructure -w -transform snakecase
16+
//go:generate gomodifytags -file $GOFILE -struct PageTitleProperty -clear-tags -w
17+
//go:generate gomodifytags --file $GOFILE --struct PageTitleProperty -add-tags json,mapstructure -w -transform snakecase
1818
type PageTitleProperty struct {
1919
Type object.PropertyType `json:"type" mapstructure:"type"`
2020
ID string `json:"id" mapstructure:"id"`
21-
Title []RichText `json:"title" mapstructure:"title"`
21+
Title []TextObject `json:"title" mapstructure:"title"`
2222
}
2323

2424
// GetType returns the type of the property.
@@ -32,7 +32,7 @@ func (p *PageTitleProperty) GetType() object.PropertyType {
3232
type DatabaseTitleProperty struct {
3333
Type object.PropertyType `json:"type" mapstructure:"type"`
3434
ID string `json:"id" mapstructure:"id"`
35-
Title *RichText `json:"title" mapstructure:"title"`
35+
Title *TextObject `json:"title" mapstructure:"title"`
3636
}
3737

3838
// GetType returns the type of the property.
@@ -46,7 +46,7 @@ func (p *DatabaseTitleProperty) GetType() object.PropertyType {
4646
type TextProperty struct {
4747
Type object.PropertyType `json:"type" mapstructure:"type"`
4848
ID string `json:"id" mapstructure:"id"`
49-
Text []RichText `json:"text" mapstructure:"text"`
49+
Text interface{} `json:"text" mapstructure:"text"`
5050
}
5151

5252
// GetType returns the type of the property.

notion/rich_text.go

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,9 @@ const (
99
Equation RichTextType = "equation"
1010
)
1111

12-
// RichText object represents Notion rich text object
13-
//
14-
// API doc: https://developers.notion.com/reference/rich-text
15-
//go:generate gomodifytags -file $GOFILE -struct RichText -clear-tags -w
16-
//go:generate gomodifytags --file $GOFILE --struct RichText -add-tags json,mapstructure -w -transform snakecase
17-
type RichText struct {
18-
PlainText string `json:"plain_text" mapstructure:"plain_text"`
19-
Href string `json:"href" mapstructure:"href"`
20-
Annotations *Annotations `json:"annotations" mapstructure:"annotations"`
21-
Type RichTextType `json:"type" mapstructure:"type"`
12+
// RicchText is descibed in API doc: https://developers.notion.com/reference/rich-text
13+
type RichText interface {
14+
GetType() RichTextType
2215
}
2316

2417
// Annotations object represents Notion rich text annotation
@@ -62,16 +55,33 @@ const (
6255
//go:generate gomodifytags -file $GOFILE -struct TextObject -clear-tags -w
6356
//go:generate gomodifytags --file $GOFILE --struct TextObject -add-tags json,mapstructure -w -transform snakecase
6457
type TextObject struct {
65-
Content string `json:"content" mapstructure:"content"`
66-
Link *LinkObject `json:"link" mapstructure:"link"`
58+
PlainText string `json:"plain_text" mapstructure:"plain_text"`
59+
Href string `json:"href" mapstructure:"href"`
60+
Annotations *Annotations `json:"annotations" mapstructure:"annotations"`
61+
Type RichTextType `json:"type" mapstructure:"type"`
62+
Content string `json:"content" mapstructure:"content"`
63+
Link *LinkObject `json:"link" mapstructure:"link"`
64+
}
65+
66+
// GetType returns the object type
67+
func (obj *TextObject) GetType() RichTextType {
68+
return obj.Type
6769
}
6870

6971
// LinkObject object represents Notion rich text object
7072
//go:generate gomodifytags -file $GOFILE -struct LinkObject -clear-tags -w
7173
//go:generate gomodifytags --file $GOFILE --struct LinkObject -add-tags json,mapstructure -w -transform snakecase
7274
type LinkObject struct {
73-
Type string `json:"type" mapstructure:"type"`
74-
URL string `json:"url" mapstructure:"url"`
75+
PlainText string `json:"plain_text" mapstructure:"plain_text"`
76+
Href string `json:"href" mapstructure:"href"`
77+
Annotations *Annotations `json:"annotations" mapstructure:"annotations"`
78+
Type RichTextType `json:"type" mapstructure:"type"`
79+
URL string `json:"url" mapstructure:"url"`
80+
}
81+
82+
// GetType returns the object type
83+
func (obj *LinkObject) GetType() RichTextType {
84+
return obj.Type
7585
}
7686

7787
// MentionObjectType is for types of mentions.
@@ -84,18 +94,35 @@ const (
8494
DateionObject MentionObjectType = "date"
8595
)
8696

87-
// TextObject object represents Notion rich text object
88-
//go:generate gomodifytags -file $GOFILE -struct TextObject -clear-tags -w
89-
//go:generate gomodifytags --file $GOFILE --struct TextObject -add-tags json,mapstructure -w -transform snakecase
97+
// MentionObject object represents Notion rich text object
98+
//go:generate gomodifytags -file $GOFILE -struct MentionObject -clear-tags -w
99+
//go:generate gomodifytags --file $GOFILE --struct MentionObject -add-tags json,mapstructure -w -transform snakecase
90100
type MentionObject struct {
91-
Type MentionObjectType
92-
Database *Database
93-
User *User
101+
PlainText string `json:"plain_text" mapstructure:"plain_text"`
102+
Href string `json:"href" mapstructure:"href"`
103+
Annotations *Annotations `json:"annotations" mapstructure:"annotations"`
104+
Type RichTextType `json:"type" mapstructure:"type"`
105+
Database *Database `json:"database" mapstructure:"database"`
106+
User *User `json:"user" mapstructure:"user"`
107+
}
108+
109+
// GetType returns the object type
110+
func (obj *MentionObject) GetType() RichTextType {
111+
return obj.Type
94112
}
95113

96114
// EquationObject object represents Notion rich text object
97115
//go:generate gomodifytags -file $GOFILE -struct EquationObject -clear-tags -w
98116
//go:generate gomodifytags --file $GOFILE --struct EquationObject -add-tags json,mapstructure -w -transform snakecase
99117
type EquationObject struct {
100-
Expression string `json:"expression" mapstructure:"expression"`
118+
PlainText string `json:"plain_text" mapstructure:"plain_text"`
119+
Href string `json:"href" mapstructure:"href"`
120+
Annotations *Annotations `json:"annotations" mapstructure:"annotations"`
121+
Type RichTextType `json:"type" mapstructure:"type"`
122+
Expression string `json:"expression" mapstructure:"expression"`
123+
}
124+
125+
// GetType returns the object type
126+
func (obj *EquationObject) GetType() RichTextType {
127+
return obj.Type
101128
}

notion/search_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestSearchService_Search(t *testing.T) {
131131
ID: "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6",
132132
CreatedTime: "2021-04-22T22:23:26.080Z",
133133
LastEditedTime: "2021-04-23T04:21:00.000Z",
134-
Title: []RichText{
134+
Title: []TextObject{
135135
{
136136
PlainText: "Tasks",
137137
Annotations: &Annotations{Color: "default"},
@@ -140,7 +140,7 @@ func TestSearchService_Search(t *testing.T) {
140140
},
141141

142142
Properties: map[string]Property{
143-
"Name": &DatabaseTitleProperty{Type: "title", ID: "title", Title: &RichText{}},
143+
"Name": &DatabaseTitleProperty{Type: "title", ID: "title", Title: &TextObject{}},
144144
"Task Type": &MultiSelectProperty{Type: "multi_select", ID: "vd@l"},
145145
},
146146
},
@@ -171,7 +171,7 @@ func TestSearchService_Search(t *testing.T) {
171171
Properties: map[string]Property{
172172
"Name": &PageTitleProperty{
173173
ID: "title",
174-
Title: []RichText{
174+
Title: []TextObject{
175175
{
176176
PlainText: "Task 1",
177177
Annotations: &Annotations{Color: "default"},

0 commit comments

Comments
 (0)