Skip to content

Commit

Permalink
Add GetParent to block interface (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierce-m authored Aug 17, 2023
1 parent a86cf10 commit 430a6b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ type Block interface {
GetLastEditedBy() *User
GetHasChildren() bool
GetArchived() bool
GetParent() *Parent
}

type Blocks []Block
Expand Down Expand Up @@ -252,6 +253,7 @@ type BasicBlock struct {
LastEditedBy *User `json:"last_edited_by,omitempty"`
HasChildren bool `json:"has_children,omitempty"`
Archived bool `json:"archived,omitempty"`
Parent *Parent `json:"parent,omitempty"`
}

func (b BasicBlock) GetType() BlockType {
Expand Down Expand Up @@ -290,6 +292,10 @@ func (b BasicBlock) GetArchived() bool {
return b.Archived
}

func (b BasicBlock) GetParent() *Parent {
return b.Parent
}

var _ Block = (*BasicBlock)(nil)

type ParagraphBlock struct {
Expand Down
4 changes: 4 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ func TestBlockClient(t *testing.T) {
ID: "some_id",
},
HasChildren: true,
Parent: &notionapi.Parent{
Type: "page_id",
PageID: "59833787-2cf9-4fdf-8782-e53db20768a5",
},
},
ChildPage: struct {
Title string `json:"title"`
Expand Down
4 changes: 4 additions & 0 deletions testdata/block_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
"type": "child_page",
"child_page": {
"title": "Hello"
},
"parent": {
"type": "page_id",
"page_id": "59833787-2cf9-4fdf-8782-e53db20768a5"
}
}

0 comments on commit 430a6b9

Please sign in to comment.