mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-15 00:05:04 +02:00
Add support for Page's Icon retrieval and updates (#21)
* Add support for Page's Icon retrieval and updates * Add support for creating a page with an icon * Fix tests, add icon validation * Remove unknown icon type `file` * Add icon support for "create database" endpoint Co-authored-by: David Stotijn <dstotijn@gmail.com>
This commit is contained in:
@ -15,6 +15,7 @@ type Database struct {
|
||||
Title []RichText `json:"title"`
|
||||
Properties DatabaseProperties `json:"properties"`
|
||||
Parent Parent `json:"parent"`
|
||||
Icon Icon `json:"icon"`
|
||||
}
|
||||
|
||||
// DatabaseProperties is a mapping of properties defined on a database.
|
||||
@ -235,6 +236,7 @@ type CreateDatabaseParams struct {
|
||||
ParentPageID string
|
||||
Title []RichText
|
||||
Properties DatabaseProperties
|
||||
Icon *Icon
|
||||
}
|
||||
|
||||
type (
|
||||
@ -362,6 +364,11 @@ func (p CreateDatabaseParams) Validate() error {
|
||||
if p.Properties == nil {
|
||||
return errors.New("database properties are required")
|
||||
}
|
||||
if p.Icon != nil {
|
||||
if err := p.Icon.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -372,6 +379,7 @@ func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) {
|
||||
Parent Parent `json:"parent"`
|
||||
Title []RichText `json:"title,omitempty"`
|
||||
Properties DatabaseProperties `json:"properties"`
|
||||
Icon *Icon `json:"icon,omitempty"`
|
||||
}
|
||||
|
||||
parent := Parent{
|
||||
@ -383,6 +391,7 @@ func (p CreateDatabaseParams) MarshalJSON() ([]byte, error) {
|
||||
Parent: parent,
|
||||
Title: p.Title,
|
||||
Properties: p.Properties,
|
||||
Icon: p.Icon,
|
||||
}
|
||||
|
||||
return json.Marshal(dto)
|
||||
|
Reference in New Issue
Block a user