mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-08 23:46:12 +02:00
Add missing database property types
This commit is contained in:
parent
e5130d1fde
commit
1d8c71b79b
46
database.go
46
database.go
@ -69,6 +69,50 @@ type RollupResult struct {
|
|||||||
Array []DatabasePageProperty `json:"array,omitempty"`
|
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 {
|
type DatabaseProperty struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type DatabasePropertyType `json:"type"`
|
Type DatabasePropertyType `json:"type"`
|
||||||
@ -222,7 +266,7 @@ const (
|
|||||||
DBPropTypeMultiSelect DatabasePropertyType = "multi_select"
|
DBPropTypeMultiSelect DatabasePropertyType = "multi_select"
|
||||||
DBPropTypeDate DatabasePropertyType = "date"
|
DBPropTypeDate DatabasePropertyType = "date"
|
||||||
DBPropTypePeople DatabasePropertyType = "people"
|
DBPropTypePeople DatabasePropertyType = "people"
|
||||||
DBPropTypeFile DatabasePropertyType = "file"
|
DBPropTypeFiles DatabasePropertyType = "files"
|
||||||
DBPropTypeCheckbox DatabasePropertyType = "checkbox"
|
DBPropTypeCheckbox DatabasePropertyType = "checkbox"
|
||||||
DBPropTypeURL DatabasePropertyType = "url"
|
DBPropTypeURL DatabasePropertyType = "url"
|
||||||
DBPropTypeEmail DatabasePropertyType = "email"
|
DBPropTypeEmail DatabasePropertyType = "email"
|
||||||
|
75
page.go
75
page.go
@ -45,15 +45,25 @@ type DatabasePageProperty struct {
|
|||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Type DatabasePropertyType `json:"type,omitempty"`
|
Type DatabasePropertyType `json:"type,omitempty"`
|
||||||
|
|
||||||
Title []RichText `json:"title,omitempty"`
|
Title []RichText `json:"title,omitempty"`
|
||||||
RichText []RichText `json:"rich_text,omitempty"`
|
RichText []RichText `json:"rich_text,omitempty"`
|
||||||
Number *float64 `json:"number,omitempty"`
|
Number *float64 `json:"number,omitempty"`
|
||||||
Select *SelectOptions `json:"select,omitempty"`
|
Select *SelectOptions `json:"select,omitempty"`
|
||||||
MultiSelect []SelectOptions `json:"multi_select,omitempty"`
|
MultiSelect []SelectOptions `json:"multi_select,omitempty"`
|
||||||
Date *Date `json:"date,omitempty"`
|
Date *Date `json:"date,omitempty"`
|
||||||
Formula *FormulaResult `json:"formula,omitempty"`
|
Formula *FormulaResult `json:"formula,omitempty"`
|
||||||
Relation []Relation `json:"relation,omitempty"`
|
Relation []Relation `json:"relation,omitempty"`
|
||||||
Rollup *RollupResult `json:"rollup,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.
|
// CreatePageParams are the params used for creating a page.
|
||||||
@ -82,6 +92,53 @@ const (
|
|||||||
ParentTypePage ParentType = "page_id"
|
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 {
|
func (p CreatePageParams) Validate() error {
|
||||||
if p.ParentType == "" {
|
if p.ParentType == "" {
|
||||||
return errors.New("parent type is required")
|
return errors.New("parent type is required")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user