1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2025-06-08 23:46:12 +02:00

Add description field to Database struct type (#34)

This commit is contained in:
David Stotijn 2022-08-14 19:40:30 +02:00 committed by GitHub
parent df02b41099
commit b6e74a67d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 113 additions and 18 deletions

View File

@ -995,6 +995,13 @@ func TestCreateDatabase(t *testing.T) {
}, },
}, },
}, },
Description: []notion.RichText{
{
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
},
},
},
Properties: notion.DatabaseProperties{ Properties: notion.DatabaseProperties{
"Title": notion.DatabaseProperty{ "Title": notion.DatabaseProperty{
Type: notion.DBPropTypeTitle, Type: notion.DBPropTypeTitle,
@ -1040,6 +1047,25 @@ func TestCreateDatabase(t *testing.T) {
"href": null "href": null
} }
], ],
"description": [
{
"type": "text",
"text": {
"content": "Lorem ipsum dolor sit amet.",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Lorem ipsum dolor sit amet.",
"href": null
}
],
"properties": { "properties": {
"Title": { "Title": {
"id": "title", "id": "title",
@ -1078,6 +1104,13 @@ func TestCreateDatabase(t *testing.T) {
}, },
}, },
}, },
"description": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Lorem ipsum dolor sit amet.",
},
},
},
"properties": map[string]interface{}{ "properties": map[string]interface{}{
"Title": map[string]interface{}{ "Title": map[string]interface{}{
"type": "title", "type": "title",
@ -1117,6 +1150,18 @@ func TestCreateDatabase(t *testing.T) {
PlainText: "Foobar", PlainText: "Foobar",
}, },
}, },
Description: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{
Content: "Lorem ipsum dolor sit amet.",
},
Annotations: &notion.Annotations{
Color: notion.ColorDefault,
},
PlainText: "Lorem ipsum dolor sit amet.",
},
},
Properties: notion.DatabaseProperties{ Properties: notion.DatabaseProperties{
"Title": notion.DatabaseProperty{ "Title": notion.DatabaseProperty{
ID: "title", ID: "title",
@ -1284,6 +1329,13 @@ func TestUpdateDatabase(t *testing.T) {
}, },
}, },
}, },
Description: []notion.RichText{
{
Text: &notion.Text{
Content: "Updated description.",
},
},
},
Properties: map[string]*notion.DatabaseProperty{ Properties: map[string]*notion.DatabaseProperty{
"New": { "New": {
Type: notion.DBPropTypeRichText, Type: notion.DBPropTypeRichText,
@ -1330,6 +1382,25 @@ func TestUpdateDatabase(t *testing.T) {
"href": null "href": null
} }
], ],
"description": [
{
"type": "text",
"text": {
"content": "Updated description.",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Updated description.",
"href": null
}
],
"properties": { "properties": {
"Name": { "Name": {
"id": "title", "id": "title",
@ -1369,6 +1440,13 @@ func TestUpdateDatabase(t *testing.T) {
}, },
}, },
}, },
"description": []interface{}{
map[string]interface{}{
"text": map[string]interface{}{
"content": "Updated description.",
},
},
},
"properties": map[string]interface{}{ "properties": map[string]interface{}{
"New": map[string]interface{}{ "New": map[string]interface{}{
"type": "rich_text", "type": "rich_text",
@ -1405,6 +1483,18 @@ func TestUpdateDatabase(t *testing.T) {
PlainText: "Grocery List", PlainText: "Grocery List",
}, },
}, },
Description: []notion.RichText{
{
Type: notion.RichTextTypeText,
Text: &notion.Text{
Content: "Updated description.",
},
Annotations: &notion.Annotations{
Color: notion.ColorDefault,
},
PlainText: "Updated description.",
},
},
Properties: notion.DatabaseProperties{ Properties: notion.DatabaseProperties{
"Name": notion.DatabaseProperty{ "Name": notion.DatabaseProperty{
ID: "title", ID: "title",

View File

@ -16,6 +16,7 @@ type Database struct {
LastEditedBy BaseUser `json:"last_edited_by"` LastEditedBy BaseUser `json:"last_edited_by"`
URL string `json:"url"` URL string `json:"url"`
Title []RichText `json:"title"` Title []RichText `json:"title"`
Description []RichText `json:"description"`
Properties DatabaseProperties `json:"properties"` Properties DatabaseProperties `json:"properties"`
Parent Parent `json:"parent"` Parent Parent `json:"parent"`
Icon *Icon `json:"icon,omitempty"` Icon *Icon `json:"icon,omitempty"`
@ -298,6 +299,7 @@ type DatabaseQuerySort struct {
type CreateDatabaseParams struct { type CreateDatabaseParams struct {
ParentPageID string ParentPageID string
Title []RichText Title []RichText
Description []RichText
Properties DatabaseProperties Properties DatabaseProperties
Icon *Icon Icon *Icon
Cover *Cover Cover *Cover
@ -472,12 +474,13 @@ func (p CreateDatabaseParams) Validate() error {
// MarshalJSON implements json.Marshaler. // MarshalJSON implements json.Marshaler.
func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) { func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) {
type CreatePageParamsDTO struct { type CreatePageParamsDTO struct {
Parent Parent `json:"parent"` Parent Parent `json:"parent"`
Title []RichText `json:"title,omitempty"` Title []RichText `json:"title,omitempty"`
Properties DatabaseProperties `json:"properties"` Description []RichText `json:"description,omitempty"`
Icon *Icon `json:"icon,omitempty"` Properties DatabaseProperties `json:"properties"`
Cover *Cover `json:"cover,omitempty"` Icon *Icon `json:"icon,omitempty"`
IsInline bool `json:"is_inline,omitempty"` Cover *Cover `json:"cover,omitempty"`
IsInline bool `json:"is_inline,omitempty"`
} }
parent := Parent{ parent := Parent{
@ -486,12 +489,13 @@ func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) {
} }
dto := CreatePageParamsDTO{ dto := CreatePageParamsDTO{
Parent: parent, Parent: parent,
Title: p.Title, Title: p.Title,
Properties: p.Properties, Description: p.Description,
Icon: p.Icon, Properties: p.Properties,
Cover: p.Cover, Icon: p.Icon,
IsInline: p.IsInline, Cover: p.Cover,
IsInline: p.IsInline,
} }
return json.Marshal(dto) return json.Marshal(dto)
@ -499,12 +503,13 @@ func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) {
// UpdateDatabaseParams are the params used for updating a database. // UpdateDatabaseParams are the params used for updating a database.
type UpdateDatabaseParams struct { type UpdateDatabaseParams struct {
Title []RichText `json:"title,omitempty"` Title []RichText `json:"title,omitempty"`
Properties map[string]*DatabaseProperty `json:"properties,omitempty"` Description []RichText `json:"description,omitempty"`
Icon *Icon `json:"icon,omitempty"` Properties map[string]*DatabaseProperty `json:"properties,omitempty"`
Cover *Cover `json:"cover,omitempty"` Icon *Icon `json:"icon,omitempty"`
Archived *bool `json:"archived,omitempty"` Cover *Cover `json:"cover,omitempty"`
IsInline *bool `json:"is_inline,omitempty"` Archived *bool `json:"archived,omitempty"`
IsInline *bool `json:"is_inline,omitempty"`
} }
// Validate validates params for updating a database. // Validate validates params for updating a database.