Skip to content

Commit

Permalink
Fix database page property types
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
dstotijn committed May 24, 2021
1 parent 14d2e8c commit c675641
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 46 deletions.
160 changes: 160 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,86 @@ func TestQueryDatabase(t *testing.T) {
"type": "number",
"number": 42
},
"People": {
"id": "1#nc",
"type": "people",
"people": [
{
"id": "be32e790-8292-46df-a248-b784fdf483cf",
"name": "Jane Doe",
"avatar_url": "https://example.com/image.png",
"type": "person",
"person": {
"email": "[email protected]"
}
}
]
},
"Files": {
"id": "!$9x",
"type": "files",
"files": [
{
"name": "foobar.pdf"
}
]
},
"Checkbox": {
"id": "49S@",
"type": "checkbox",
"checkbox": true
},
"URL": {
"id": "93$$",
"type": "url",
"url": "https://example.com"
},
"Email": {
"id": "xb3Q",
"type": "email",
"email": "[email protected]"
},
"PhoneNumber": {
"id": "c2#Q",
"type": "phone_number",
"phone_number": "867-5309"
},
"CreatedTime": {
"id": "s#0s",
"type": "created_time",
"created_time": "2021-05-24T15:44:09.123Z"
},
"CreatedBy": {
"id": "49S@",
"type": "created_by",
"created_by": {
"id": "be32e790-8292-46df-a248-b784fdf483cf",
"name": "Jane Doe",
"avatar_url": "https://example.com/image.png",
"type": "person",
"person": {
"email": "[email protected]"
}
}
},
"LastEditedTime": {
"id": "x#0s",
"type": "last_edited_time",
"last_edited_time": "2021-05-24T15:44:09.123Z"
},
"LastEditedBy": {
"id": "x9S@",
"type": "last_edited_by",
"last_edited_by": {
"id": "be32e790-8292-46df-a248-b784fdf483cf",
"name": "Jane Doe",
"avatar_url": "https://example.com/image.png",
"type": "person",
"person": {
"email": "[email protected]"
}
}
},
"Calculation": {
"id": "s(4f",
"type": "formula",
Expand Down Expand Up @@ -576,6 +656,35 @@ func TestQueryDatabase(t *testing.T) {
Type: notion.DBPropTypeNumber,
Number: notion.Float64Ptr(42),
},
"People": notion.DatabasePageProperty{
ID: "1#nc",
Type: notion.DBPropTypePeople,
People: []notion.User{
{
ID: "be32e790-8292-46df-a248-b784fdf483cf",
Name: "Jane Doe",
AvatarURL: notion.StringPtr("https://example.com/image.png"),
Type: "person",
Person: &notion.Person{
Email: "[email protected]",
},
},
},
},
"Files": notion.DatabasePageProperty{
ID: "!$9x",
Type: notion.DBPropTypeFiles,
Files: []notion.File{
{
Name: "foobar.pdf",
},
},
},
"Checkbox": notion.DatabasePageProperty{
ID: "49S@",
Type: notion.DBPropTypeCheckbox,
Checkbox: notion.BoolPtr(true),
},
"Calculation": notion.DatabasePageProperty{
ID: "s(4f",
Type: notion.DBPropTypeFormula,
Expand All @@ -584,6 +693,57 @@ func TestQueryDatabase(t *testing.T) {
Number: notion.Float64Ptr(float64(42)),
},
},
"URL": notion.DatabasePageProperty{
ID: "93$$",
Type: notion.DBPropTypeURL,
URL: notion.StringPtr("https://example.com"),
},
"Email": notion.DatabasePageProperty{
ID: "xb3Q",
Type: notion.DBPropTypeEmail,
Email: notion.StringPtr("[email protected]"),
},
"PhoneNumber": notion.DatabasePageProperty{
ID: "c2#Q",
Type: notion.DBPropTypePhoneNumber,
PhoneNumber: notion.StringPtr("867-5309"),
},
"CreatedTime": notion.DatabasePageProperty{
ID: "s#0s",
Type: notion.DBPropTypeCreatedTime,
CreatedTime: notion.TimePtr(mustParseTime(time.RFC3339Nano, "2021-05-24T15:44:09.123Z")),
},
"CreatedBy": notion.DatabasePageProperty{
ID: "49S@",
Type: notion.DBPropTypeCreatedBy,
CreatedBy: &notion.User{
ID: "be32e790-8292-46df-a248-b784fdf483cf",
Name: "Jane Doe",
AvatarURL: notion.StringPtr("https://example.com/image.png"),
Type: "person",
Person: &notion.Person{
Email: "[email protected]",
},
},
},
"LastEditedTime": notion.DatabasePageProperty{
ID: "x#0s",
Type: notion.DBPropTypeLastEditedTime,
LastEditedTime: notion.TimePtr(mustParseTime(time.RFC3339Nano, "2021-05-24T15:44:09.123Z")),
},
"LastEditedBy": notion.DatabasePageProperty{
ID: "x9S@",
Type: notion.DBPropTypeLastEditedBy,
LastEditedBy: &notion.User{
ID: "be32e790-8292-46df-a248-b784fdf483cf",
Name: "Jane Doe",
AvatarURL: notion.StringPtr("https://example.com/image.png"),
Type: "person",
Person: &notion.Person{
Email: "[email protected]",
},
},
},
"Relation": notion.DatabasePageProperty{
ID: "Cxl[",
Type: notion.DBPropTypeRelation,
Expand Down
36 changes: 0 additions & 36 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,46 +73,10 @@ type People struct {
People []User `json:"people"`
}

type Files struct {
Files []File `json:"people"`
}

type File struct {
Name string `json:"name"`
}

type Checkbox struct {
Checkbox bool `json:"checked"`
}

type URL struct {
URL string `json:"url"`
}

type Email struct {
Email string `json:"email"`
}

type PhoneNumber struct {
PhoneNumber string `json:"phone_number"`
}

type CreatedTime struct {
CreatedTime time.Time `json:"created_time"`
}

type CreatedBy struct {
CreatedBy User `json:"created_by"`
}

type LastEditedTime struct {
LastEditedTime time.Time `json:"last_edited_time"`
}

type LastEditedBy struct {
LastEditedBy User `json:"last_edited_by"`
}

type DatabaseProperty struct {
ID string `json:"id"`
Type DatabasePropertyType `json:"type"`
Expand Down
20 changes: 10 additions & 10 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ type DatabasePageProperty struct {
Formula *FormulaResult `json:"formula,omitempty"`
Relation []Relation `json:"relation,omitempty"`
Rollup *RollupResult `json:"rollup,omitempty"`
People *People `json:"people,omitempty"`
Files *Files `json:"files,omitempty"`
Checkbox *Checkbox `json:"checkbox,omitempty"`
URL *URL `json:"url,omitempty"`
Email *Email `json:"email,omitempty"`
PhoneNumber *PhoneNumber `json:"phone_number,omitempty"`
CreatedTime *CreatedTime `json:"created_time,omitempty"`
CreatedBy *CreatedBy `json:"created_by,omitempty"`
LastEditedTime *LastEditedTime `json:"last_edited_time,omitempty"`
LastEditedBy *LastEditedBy `json:"last_edited_by,omitempty"`
People []User `json:"people,omitempty"`
Files []File `json:"files,omitempty"`
Checkbox *bool `json:"checkbox,omitempty"`
URL *string `json:"url,omitempty"`
Email *string `json:"email,omitempty"`
PhoneNumber *string `json:"phone_number,omitempty"`
CreatedTime *time.Time `json:"created_time,omitempty"`
CreatedBy *User `json:"created_by,omitempty"`
LastEditedTime *time.Time `json:"last_edited_time,omitempty"`
LastEditedBy *User `json:"last_edited_by,omitempty"`
}

// CreatePageParams are the params used for creating a page.
Expand Down

0 comments on commit c675641

Please sign in to comment.