10000 Merge pull request #297 from notion-dotnet/259-update-parent-field-fo… · notion-dotnet/notion-sdk-net@3e54645 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e54645

Browse files
Merge pull request #297 from notion-dotnet/259-update-parent-field-for-page-database-and-block
Update parent field for Page, Database and Block object
2 parents 56f5dd5 + 47d331d commit 3e54645

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

Src/Notion.Client/Models/Blocks/Block.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Notion.Client.Models.Blocks;
23

34
namespace Notion.Client
45
{
@@ -19,5 +20,10 @@ public abstract class Block : IBlock
1920
public PartialUser CreatedBy { get; set; }
2021

2122
public PartialUser LastEditedBy { get; set; }
23+
24+
/// <summary>
25+
/// Information about the block's parent.
26+
/// </summary>
27+
public IBlockParent Parent { get; set; }
2228
}
2329
}

Src/Notion.Client/Models/Blocks/IBlock.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using JsonSubTypes;
22
using Newtonsoft.Json;
33
using Newtonsoft.Json.Converters;
4+
using Notion.Client.Models.Blocks;
45

56
namespace Notion.Client
67
{
@@ -44,5 +45,8 @@ public interface IBlock : IObject, IObjectModificationData
4445

4546
[JsonProperty("has_children")]
4647
bool HasChildren { get; set; }
48+
49+
[JsonProperty("parent")]
50+
IBlockParent Parent { get; set; }
4751
}
4852
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client.Models.Blocks
5+
{
6+
[JsonConverter(typeof(JsonSubtypes), "type")]
7+
[JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)]
8+
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
9+
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
10+
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
11+
public interface IBlockParent
12+
{
13+
}
14+
}

Src/Notion.Client/Models/Database/IDatabaseParent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Notion.Client
66
[JsonConverter(typeof(JsonSubtypes), "type")]
77
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
88
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
9+
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
910
public interface IDatabaseParent : IParent
1011
{
1112
}

Src/Notion.Client/Models/Page/IPageParent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Notion.Client
77
[JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)]
88
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
99
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
10+
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
1011
public interface IPageParent : IParent
1112
{
1213
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class BlockParent : IPageParent, IDatabaseParent
6+
{
7+
/// <summary>
8+
/// Always has a value "block_id"
9+
/// </summary>
10+
public ParentType Type { get; set; }
11+
12+
/// <summary>
13+
/// The ID of the block that the element belongs to.
14+
/// </summary>
15+
[JsonProperty("block_id")]
16+
public string BlockId { get; set; }
17+
}
18+
}

Src/Notion.Client/Models/Parents/ParentType.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public enum ParentType
1414
PageId,
1515

1616
[EnumMember(< 341A span class=pl-s1>Value = "workspace")]
17-
Workspace
17+
Workspace,
18+
19+
[EnumMember(Value = "block_id")]
20+
BlockId,
1821
}
1922
}

0 commit comments

Comments
 (0)
0