diff --git a/block.go b/block.go index 70e14d9..d0d984f 100644 --- a/block.go +++ b/block.go @@ -10,6 +10,7 @@ import ( // See: https://developers.notion.com/reference/block type Block interface { ID() string + Parent() Parent CreatedTime() time.Time LastEditedTime() time.Time HasChildren() bool @@ -19,6 +20,7 @@ type Block interface { type blockDTO struct { ID string `json:"id,omitempty"` + Parent *Parent `json:"parent,omitempty"` Type BlockType `json:"type,omitempty"` CreatedTime *time.Time `json:"created_time,omitempty"` LastEditedTime *time.Time `json:"last_edited_time,omitempty"` @@ -60,6 +62,7 @@ type blockDTO struct { type baseBlock struct { id string + parent Parent createdTime time.Time lastEditedTime time.Time hasChildren bool @@ -87,6 +90,10 @@ func (b baseBlock) Archived() bool { return b.archived } +func (b baseBlock) Parent() Parent { + return b.parent +} + type ParagraphBlock struct { baseBlock @@ -831,6 +838,10 @@ func (dto blockDTO) Block() Block { hasChildren: dto.HasChildren, } + if dto.Parent != nil { + baseBlock.parent = *dto.Parent + } + if dto.CreatedTime != nil { baseBlock.createdTime = *dto.CreatedTime } diff --git a/client_test.go b/client_test.go index 6ac0518..7e187b7 100644 --- a/client_test.go +++ b/client_test.go @@ -3998,6 +3998,7 @@ func TestFindBlockByID(t *testing.T) { respStatusCode int expBlock notion.Block expID string + expParent notion.Parent expCreatedTime time.Time expLastEditedTime time.Time expHasChildren bool @@ -4012,6 +4013,10 @@ func TestFindBlockByID(t *testing.T) { `{ "object": "block", "id": "048e165e-352d-4119-8128-e46c3527d95c", + "parent": { + "type": "page_id", + "page_id": "59833787-2cf9-4fdf-8782-e53db20768a5" + }, "created_time": "2021-10-02T06:09:00.000Z", "last_edited_time": "2021-10-02T06:31:00.000Z", "has_children": true, @@ -4027,7 +4032,11 @@ func TestFindBlockByID(t *testing.T) { expBlock: ¬ion.ChildPageBlock{ Title: "test title", }, - expID: "048e165e-352d-4119-8128-e46c3527d95c", + expID: "048e165e-352d-4119-8128-e46c3527d95c", + expParent: notion.Parent{ + Type: notion.ParentTypePage, + PageID: "59833787-2cf9-4fdf-8782-e53db20768a5", + }, expCreatedTime: mustParseTime(time.RFC3339, "2021-10-02T06:09:00Z"), expLastEditedTime: mustParseTime(time.RFC3339, "2021-10-02T06:31:00Z"), expHasChildren: true, @@ -4088,6 +4097,10 @@ func TestFindBlockByID(t *testing.T) { t.Fatalf("id not equal (expected: %v, got: %v)", tt.expID, block.ID()) } + if tt.expParent != block.Parent() { + t.Fatalf("parent not equal (expected: %+v, got: %+v)", tt.expParent, block.Parent()) + } + if tt.expCreatedTime != block.CreatedTime() { t.Fatalf("createdTime not equal (expected: %v, got: %v)", tt.expCreatedTime, block.CreatedTime()) } diff --git a/parent.go b/parent.go index 3f1de2d..0bf2652 100644 --- a/parent.go +++ b/parent.go @@ -3,6 +3,7 @@ package notion type Parent struct { Type ParentType `json:"type,omitempty"` + BlockID string `json:"block_id,omitempty"` PageID string `json:"page_id,omitempty"` DatabaseID string `json:"database_id,omitempty"` Workspace bool `json:"workspace,omitempty"`