mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-08 23:46:12 +02:00
Fix incorrect types for Formula
, Relation
and Rollup
page props
Fixes #11
This commit is contained in:
parent
7e83ec7aec
commit
e5130d1fde
@ -471,6 +471,41 @@ func TestQueryDatabase(t *testing.T) {
|
|||||||
"href": null
|
"href": null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"Age": {
|
||||||
|
"id": "$9nb",
|
||||||
|
"type": "number",
|
||||||
|
"number": 42
|
||||||
|
},
|
||||||
|
"Calculation": {
|
||||||
|
"id": "s(4f",
|
||||||
|
"type": "formula",
|
||||||
|
"formula": {
|
||||||
|
"type": "number",
|
||||||
|
"number": 42
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Relation": {
|
||||||
|
"id": "Cxl[",
|
||||||
|
"type": "relation",
|
||||||
|
"relation": [
|
||||||
|
{
|
||||||
|
"id": "2be9597f-693f-4b87-baf9-efc545d38ebe"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Rollup": {
|
||||||
|
"id": "xyA}",
|
||||||
|
"type": "rollup",
|
||||||
|
"rollup": {
|
||||||
|
"type": "array",
|
||||||
|
"array": [
|
||||||
|
{
|
||||||
|
"type": "number",
|
||||||
|
"number": 42
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -536,6 +571,41 @@ func TestQueryDatabase(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"Age": notion.DatabasePageProperty{
|
||||||
|
ID: "$9nb",
|
||||||
|
Type: notion.DBPropTypeNumber,
|
||||||
|
Number: notion.Float64Ptr(42),
|
||||||
|
},
|
||||||
|
"Calculation": notion.DatabasePageProperty{
|
||||||
|
ID: "s(4f",
|
||||||
|
Type: notion.DBPropTypeFormula,
|
||||||
|
Formula: ¬ion.FormulaResult{
|
||||||
|
Type: notion.FormulaResultTypeNumber,
|
||||||
|
Number: notion.Float64Ptr(float64(42)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Relation": notion.DatabasePageProperty{
|
||||||
|
ID: "Cxl[",
|
||||||
|
Type: notion.DBPropTypeRelation,
|
||||||
|
Relation: []notion.Relation{
|
||||||
|
{
|
||||||
|
ID: "2be9597f-693f-4b87-baf9-efc545d38ebe",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Rollup": notion.DatabasePageProperty{
|
||||||
|
ID: "xyA}",
|
||||||
|
Type: notion.DBPropTypeRollup,
|
||||||
|
Rollup: ¬ion.RollupResult{
|
||||||
|
Type: notion.RollupResultTypeArray,
|
||||||
|
Array: []notion.DatabasePageProperty{
|
||||||
|
{
|
||||||
|
Type: notion.DBPropTypeNumber,
|
||||||
|
Number: notion.Float64Ptr(42),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
64
database.go
64
database.go
@ -48,6 +48,27 @@ type SelectOptions struct {
|
|||||||
Color Color `json:"color,omitempty"`
|
Color Color `json:"color,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FormulaResult struct {
|
||||||
|
Type FormulaResultType `json:"type"`
|
||||||
|
|
||||||
|
String *string `json:"string,omitempty"`
|
||||||
|
Number *float64 `json:"number,omitempty"`
|
||||||
|
Boolean *bool `json:"boolean,omitempty"`
|
||||||
|
Date *Date `json:"date,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Relation struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RollupResult struct {
|
||||||
|
Type RollupResultType `json:"type"`
|
||||||
|
|
||||||
|
Number *float64 `json:"number,omitempty"`
|
||||||
|
Date *Date `json:"date,omitempty"`
|
||||||
|
Array []DatabasePageProperty `json:"array,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type DatabaseProperty struct {
|
type DatabaseProperty struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type DatabasePropertyType `json:"type"`
|
Type DatabasePropertyType `json:"type"`
|
||||||
@ -186,6 +207,8 @@ type DatabaseQuerySort struct {
|
|||||||
type (
|
type (
|
||||||
DatabasePropertyType string
|
DatabasePropertyType string
|
||||||
NumberFormat string
|
NumberFormat string
|
||||||
|
FormulaResultType string
|
||||||
|
RollupResultType string
|
||||||
SortTimestamp string
|
SortTimestamp string
|
||||||
SortDirection string
|
SortDirection string
|
||||||
)
|
)
|
||||||
@ -225,6 +248,17 @@ const (
|
|||||||
NumberFormatWon NumberFormat = "won"
|
NumberFormatWon NumberFormat = "won"
|
||||||
NumberformatYuan NumberFormat = "yuan"
|
NumberformatYuan NumberFormat = "yuan"
|
||||||
|
|
||||||
|
// Formula result type enums.
|
||||||
|
FormulaResultTypeString FormulaResultType = "string"
|
||||||
|
FormulaResultTypeNumber FormulaResultType = "number"
|
||||||
|
FormulaResultTypeBoolean FormulaResultType = "boolean"
|
||||||
|
FormulaResultTypeDate FormulaResultType = "date"
|
||||||
|
|
||||||
|
// Rollup result type enums.
|
||||||
|
RollupResultTypeNumber RollupResultType = "number"
|
||||||
|
RollupResultTypeDate RollupResultType = "date"
|
||||||
|
RollupResultTypeArray RollupResultType = "array"
|
||||||
|
|
||||||
// Sort timestamp enums.
|
// Sort timestamp enums.
|
||||||
SortTimeStampCreatedTime SortTimestamp = "created_time"
|
SortTimeStampCreatedTime SortTimestamp = "created_time"
|
||||||
SortTimeStampLastEditedTime SortTimestamp = "last_edited_time"
|
SortTimeStampLastEditedTime SortTimestamp = "last_edited_time"
|
||||||
@ -254,3 +288,33 @@ func (prop DatabaseProperty) Metadata() interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value returns the underlying result value of an evaluated formula.
|
||||||
|
func (f FormulaResult) Value() interface{} {
|
||||||
|
switch f.Type {
|
||||||
|
case FormulaResultTypeString:
|
||||||
|
return f.String
|
||||||
|
case FormulaResultTypeNumber:
|
||||||
|
return f.Number
|
||||||
|
case FormulaResultTypeBoolean:
|
||||||
|
return f.Boolean
|
||||||
|
case FormulaResultTypeDate:
|
||||||
|
return f.Date
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the underlying result value of an evaluated rollup.
|
||||||
|
func (r RollupResult) Value() interface{} {
|
||||||
|
switch r.Type {
|
||||||
|
case RollupResultTypeNumber:
|
||||||
|
return r.Number
|
||||||
|
case RollupResultTypeDate:
|
||||||
|
return r.Date
|
||||||
|
case RollupResultTypeArray:
|
||||||
|
return r.Array
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
18
page.go
18
page.go
@ -45,15 +45,15 @@ 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 *NumberMetadata `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 *FormulaMetadata `json:"formula,omitempty"`
|
Formula *FormulaResult `json:"formula,omitempty"`
|
||||||
Relation *RelationMetadata `json:"relation,omitempty"`
|
Relation []Relation `json:"relation,omitempty"`
|
||||||
Rollup *RollupMetadata `json:"rollup,omitempty"`
|
Rollup *RollupResult `json:"rollup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePageParams are the params used for creating a page.
|
// CreatePageParams are the params used for creating a page.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user