mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-15 00:05:04 +02:00
Add parent
property to blocks (#28)
This commit is contained in:
11
block.go
11
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
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user