Skip to content

Commit 141ce94

Browse files
Move each block type into separate file 🚚
1 parent 8237380 commit 141ce94

File tree

13 files changed

+251
-205
lines changed

13 files changed

+251
-205
lines changed

Src/Notion.Client/Models/Block.cs

Lines changed: 0 additions & 205 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
4+
5+
namespace Notion.Client
6+
{
7+
[JsonConverter(typeof(JsonSubtypes), "type")]
8+
[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)]
9+
[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)]
10+
[JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)]
11+
[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)]
12+
[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)]
13+
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
14+
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
15+
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
16+
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
17+
[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)]
18+
public class BlockBase
19+
{
20+
public string Object => "block";
21+
public string Id { get; set; }
22+
23+
[JsonConverter(typeof(StringEnumConverter))]
24+
public virtual BlockType Type { get; set; }
25+
26+
[JsonProperty("created_time")]
27+
public string CreatedTime { get; set; }
28+
29+
[JsonProperty("last_edited_time")]
30+
public string LastEditedTime { get; set; }
31+
32+
[JsonProperty("has_children")]
33+
public virtual bool HasChildren { get; set; }
34+
}
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Notion.Client
4+
{
5+
public enum BlockType
6+
{
7+
[EnumMember(Value = "paragraph")]
8+
Paragraph,
9+
10+
[EnumMember(Value = "heading_1")]
11+
Heading_1,
12+
13+
[EnumMember(Value = "heading_2")]
14+
Heading_2,
15+
16+
[EnumMember(Value = "heading_3")]
17+
Heading_3,
18+
19+
[EnumMember(Value = "bulleted_list_item")]
20+
BulletedListItem,
21+
22+
[EnumMember(Value = "numbered_list_item")]
23+
NumberedListItem,
24+
25+
[EnumMember(Value = "to_do")]
26+
ToDo,
27+
28+
[EnumMember(Value = "toggle")]
29+
Toggle,
30+
31+
[EnumMember(Value = "child_page")]
32+
ChildPage,
33+
34+
[EnumMember(Value = "unsupported")]
35+
Unsupported
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class BulletedListItemBlock : BlockBase
7+
{
8+
public override BlockType Type => BlockType.BulletedListItem;
9+
10+
[JsonProperty("bulleted_list_item")]
11+
public Info BulletedListItem { get; set; }
12+
13+
public class Info
14+
{
15+
public IEnumerable<RichTextBase> Text { get; set; }
16+
public IEnumerable<BlockBase> Children { get; set; }
17+
}
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class ChildPageBlock : BlockBase
6+
{
7+
public override BlockType Type => BlockType.ChildPage;
8+
9+
[JsonProperty("child_page")]
10+
public Info ChildPage { get; set; }
11+
12+
public class Info
13+
{
14+
public string Title { get; set; }
15+
}
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class HeadingOneBlock : BlockBase
7+
{
8+
public override BlockType Type => BlockType.Heading_1;
9+
10+
[JsonProperty("heading_1")]
11+
public Info Heading_1 { get; set; }
12+
13+
public override bool HasChildren => false;
14+
15+
public class Info
16+
{
17+
public IEnumerable<RichTextBase> Text { get; set; }
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class HeadingThreeeBlock : BlockBase
7+
{
8+
public override BlockType Type => BlockType.Heading_3;
9+
10+
[JsonProperty("heading_3")]
11+
public Info Heading_3 { get; set; }
12+
13+
public override bool HasChildren => false;
14+
15+
public class Info
16+
{
17+
public IEnumerable<RichTextBase> Text { get; set; }
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class HeadingTwoBlock : BlockBase
7+
{
8+
public override BlockType Type => BlockType.Heading_2;
9+
10+
[JsonProperty("heading_2")]
11+
public Info Heading_2 { get; set; }
12+
13+
public override bool HasChildren => false;
14+
15+
public class Info
16+
{
17+
public IEnumerable<RichTextBase> Text { get; set; }
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)