Skip to content

Commit 6ce6245

Browse files
Merge pull request #81 from notion-dotnet/feature/58-database-objects-now-returns-parent-property
Database objects now returns parent property 💖
2 parents e8eb3de + 89e353b commit 6ce6245

File tree

14 files changed

+158
-15
lines changed

14 files changed

+158
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Notion.Client
77
public class Database : IObject
88
{
99
public ObjectType Object => ObjectType.Database;
10+
1011
public string Id { get; set; }
1112

1213
[JsonProperty("created_time")]
@@ -18,5 +19,7 @@ public class Database : IObject
1819
public List<RichTextBase> Title { get; set; }
1920

2021
public Dictionary<string, Property> Properties { get; set; }
22+
23+
public IDatabaseParent Parent { get; set; }
2124
}
2225
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
[JsonConverter(typeof(JsonSubtypes), "type")]
7+
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
8+
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
9+
public interface IDatabaseParent : IParent
10+
{
11+
}
12+
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
using JsonSubTypes;
22
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Converters;
43

54
namespace Notion.Client
65
{
76
[JsonConverter(typeof(JsonSubtypes), "type")]
87
[JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)]
98
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
109
[JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)]
11-
public class Parent
10+
public interface IPageParent : IParent
1211
{
13-
[JsonConverter(typeof(StringEnumConverter))]
14-
public ParentType Type { get; set; }
1512
}
1613
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public NewPage()
1717
/// Constructor that adds required <c>Parent</c> property. Used when you don't want to
1818
/// assign properties in separate operations.
1919
/// </summary>
20-
public NewPage(Parent parent)
20+
public NewPage(IPageParent parent)
2121
{
2222
Parent = parent;
2323
Properties = new Dictionary<string, PropertyValue>();
2424
Children = new List<Block>();
2525
}
2626

27-
public Parent Parent { get; set; }
27+
public IPageParent Parent { get; set; }
2828

2929
public Dictionary<string, PropertyValue> Properties { get; set; }
3030

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ namespace Notion.Client
77
public class Page : IObject
88
{
99
public ObjectType Object => ObjectType.Page;
10+
1011
public string Id { get; set; }
11-
public Parent Parent { get; set; }
12+
13+
public IPageParent Parent { get; set; }
1214

1315
[JsonProperty("created_time")]
1416
public DateTime CreatedTime { get; set; }

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

Lines changed: 0 additions & 6 deletions
This file was deleted.

Src/Notion.Client/Models/Page/DatabaseParent.cs renamed to Src/Notion.Client/Models/Parents/DatabaseParent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Notion.Client
44
{
5-
public class DatabaseParent : Parent
5+
public class DatabaseParent : IPageParent
66
{
7+
public ParentType Type { get; set; }
8+
79
[JsonProperty("database_id")]
810
public string DatabaseId { get; set; }
911
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Converters;
3+
4+
namespace Notion.Client
5+
{
6+
public interface IParent
7+
{
8+
[JsonConverter(typeof(StringEnumConverter))]
9+
ParentType Type { get; set; }
10+
}
11+
}

Src/Notion.Client/Models/Page/PageParent.cs renamed to Src/Notion.Client/Models/Parents/PageParent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Notion.Client
44
{
5-
public class PageParent : Parent
5+
public class PageParent : IPageParent, IDatabaseParent
66
{
77
[JsonProperty("page_id")]
88
public string PageId { get; set; }
9+
public ParentType Type { get; set; }
910
}
1011
}

Src/Notion.Client/Models/Page/ParentType.cs renamed to Src/Notion.Client/Models/Parents/ParentType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum ParentType
1212

1313
[EnumMember(Value = "page_id")]
1414
PageId,
15+
1516
[EnumMember(Value = "workspace")]
1617
Workspace
1718
}

0 commit comments

Comments
 (0)