Skip to content

Update parent field for Page, Database and Block object #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Src/Notion.Client/Models/Blocks/Block.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Notion.Client.Models.Blocks;

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

public PartialUser LastEditedBy { get; set; }

/// <summary>
/// Information about the block's parent.
/// </summary>
public IBlockParent Parent { get; set; }
}
}
4 changes: 4 additions & 0 deletions Src/Notion.Client/Models/Blocks/IBlock.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JsonSubTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Notion.Client.Models.Blocks;

namespace Notion.Client
{
Expand Down Expand Up @@ -44,5 +45,8 @@ public interface IBlock : IObject, IObjectModificationData

[JsonProperty("has_children")]
bool HasChildren { get; set; }

[JsonProperty("parent")]
IBlockParent Parent { get; set; }
}
}
14 changes: 14 additions & 0 deletions Src/Notion.Client/Models/Blocks/IBlockParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using JsonSubTypes;
using Newtonsoft.Json;

namespace Notion.Client.Models.Blocks
{
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)]
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
public interface IBlockParent
{
}
}
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Database/IDatabaseParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Notion.Client
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
public interface IDatabaseParent : IParent
{
}
Expand Down
1 change: 1 addition & 0 deletions Src/Notion.Client/Models/Page/IPageParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Notion.Client
[JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)]
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
public interface IPageParent : IParent
{
}
Expand Down
18 changes: 18 additions & 0 deletions Src/Notion.Client/Models/Parents/BlockParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class BlockParent : IPageParent, IDatabaseParent
{
/// <summary>
/// Always has a value "block_id"
/// </summary>
public ParentType Type { get; set; }

/// <summary>
/// The ID of the block that the element belongs to.
/// </summary>
[JsonProperty("block_id")]
public string BlockId { get; set; }
}
}
5 changes: 4 additions & 1 deletion Src/Notion.Client/Models/Parents/ParentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum ParentType
PageId,

[EnumMember(Value = "workspace")]
Workspace
Workspace,

[EnumMember(Value = "block_id")]
BlockId,
}
}