diff --git a/database.go b/database.go index dc1c5f9..95523cd 100644 --- a/database.go +++ b/database.go @@ -69,6 +69,50 @@ type RollupResult struct { Array []DatabasePageProperty `json:"array,omitempty"` } +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"` @@ -222,7 +266,7 @@ const ( DBPropTypeMultiSelect DatabasePropertyType = "multi_select" DBPropTypeDate DatabasePropertyType = "date" DBPropTypePeople DatabasePropertyType = "people" - DBPropTypeFile DatabasePropertyType = "file" + DBPropTypeFiles DatabasePropertyType = "files" DBPropTypeCheckbox DatabasePropertyType = "checkbox" DBPropTypeURL DatabasePropertyType = "url" DBPropTypeEmail DatabasePropertyType = "email" diff --git a/page.go b/page.go index 5373e43..99d4d63 100644 --- a/page.go +++ b/page.go @@ -45,15 +45,25 @@ type DatabasePageProperty struct { ID string `json:"id,omitempty"` Type DatabasePropertyType `json:"type,omitempty"` - Title []RichText `json:"title,omitempty"` - RichText []RichText `json:"rich_text,omitempty"` - Number *float64 `json:"number,omitempty"` - Select *SelectOptions `json:"select,omitempty"` - MultiSelect []SelectOptions `json:"multi_select,omitempty"` - Date *Date `json:"date,omitempty"` - Formula *FormulaResult `json:"formula,omitempty"` - Relation []Relation `json:"relation,omitempty"` - Rollup *RollupResult `json:"rollup,omitempty"` + Title []RichText `json:"title,omitempty"` + RichText []RichText `json:"rich_text,omitempty"` + Number *float64 `json:"number,omitempty"` + Select *SelectOptions `json:"select,omitempty"` + MultiSelect []SelectOptions `json:"multi_select,omitempty"` + Date *Date `json:"date,omitempty"` + 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"` } // CreatePageParams are the params used for creating a page. @@ -82,6 +92,53 @@ const ( ParentTypePage ParentType = "page_id" ) +// Value returns the underlying database page property value, based on its `type` field. +// When type is unknown/unmapped or doesn't have a value, `nil` is returned. +func (prop DatabasePageProperty) Value() interface{} { + switch prop.Type { + case DBPropTypeTitle: + return prop.Title + case DBPropTypeRichText: + return prop.RichText + case DBPropTypeNumber: + return prop.Number + case DBPropTypeSelect: + return prop.Select + case DBPropTypeMultiSelect: + return prop.MultiSelect + case DBPropTypeDate: + return prop.Date + case DBPropTypePeople: + return prop.People + case DBPropTypeFiles: + return prop.Files + case DBPropTypeCheckbox: + return prop.Checkbox + case DBPropTypeURL: + return prop.URL + case DBPropTypeEmail: + return prop.Email + case DBPropTypePhoneNumber: + return prop.PhoneNumber + case DBPropTypeFormula: + return prop.Formula + case DBPropTypeRelation: + return prop.Relation + case DBPropTypeRollup: + return prop.Rollup + case DBPropTypeCreatedTime: + return prop.CreatedTime + case DBPropTypeCreatedBy: + return prop.CreatedBy + case DBPropTypeLastEditedTime: + return prop.LastEditedTime + case DBPropTypeLastEditedBy: + return prop.LastEditedBy + default: + return nil + } +} + func (p CreatePageParams) Validate() error { if p.ParentType == "" { return errors.New("parent type is required")