8000 Merge pull request #300 from notion-dotnet/260-add-relation-single-an… · notion-dotnet/notion-sdk-net@d335c71 · GitHub
[go: up one dir, main page]

Skip to content

Commit d335c71

Browse files
Merge pull request #300 from notion-dotnet/260-add-relation-single-and-dual-type-property
Add relation single and dual property type
2 parents 317d13b + 3a42540 commit d335c71

12 files changed

+116
-40
lines changed

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

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class DualPropertyRelation : RelationData
6+
{
7+
public override RelationType Type => RelationType.Dual;
8+
9+
[JsonProperty("dual_property")]
10+
public Data DualProperty { get; set; }
11+
12+
public class Data
13+
{
14+
[JsonProperty("synced_property_name")]
15+
public string SyncedPropertyName { get; set; }
16+
17+
[JsonProperty("synced_property_id")]
18+
public string SyncedPropertyId { get; set; }
19+
}
20+
}
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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(SinglePropertyRelation), RelationType.Single)]
9+
[JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)]
10+
public abstract class RelationData
11+
{
12+
[JsonProperty("database_id")]
13+
public string DatabaseId { get; set; }
14+
15+
[JsonProperty("type")]
16+
[JsonConverter(typeof(StringEnumConverter))]
17+
public virtual RelationType Type { get; set; }
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
using Newtonsoft.Json;
4+
5+
namespace Notion.Client
6+
{
7+
public class RelationProperty : Property
8+
{
9+
public override PropertyType Type => PropertyType.Relation;
10+
11+
[JsonProperty("relation")]
12+
public RelationData Relation { get; set; }
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Notion.Client
4+
{
5+
public enum RelationType
6+
{
7+
[EnumMember(Value = "single_property")]
8+
Single,
9+
10+
[EnumMember(Value = "dual_property")]
11+
Dual
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class SinglePropertyRelation : RelationData
7+
{
8+
public override RelationType Type => RelationType.Single;
9+
10+
[JsonProperty("single_property")]
11+
public Dictionary<string, object> SingleProperty { get; set; }
12+
}
13+
}

Test/Notion.UnitTests/DatabasesClientTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,14 @@ public async Task DatabasePropertyObjectContainRelationProperty()
140140
{
141141
Id = "zDGa",
142142
Name = "Property",
143-
Relation = new Relation()
143+
Relation = new DualPropertyRelation()
144144
{
145145
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
146-
SyncedPropertyName = "Related to sample table (Property)",
147-
SyncedPropertyId = "VQ}{"
146+
DualProperty = new DualPropertyRelation.Data
147+
{
148+
SyncedPropertyName = "Related to sample table (Property)",
149+
SyncedPropertyId = "VQ}{"
150+
}
148151
}
149152
});
150153
}

Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainNameProperty.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
"type": "relation",
7272
"relation": {
7373
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
74-
"synced_property_name": "Related to sample table (Property)",
75-
"synced_property_id": "VQ}{"
74+
"type": "dual_property",
75+
"dual_property": {
76+
"synced_property_name": "Related to sample table (Property)",
77+
"synced_property_id": "VQ}{"
78+
}
7679
}
7780
},
7881
"Name": {

Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainParentProperty.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
"type": "relation",
7272
"relation": {
7373
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
74-
"synced_property_name": "Related to sample table (Property)",
75-
"synced_property_id": "VQ}{"
74+
"type": "dual_property",
75+
"dual_property": {
76+
"synced_property_name": "Related to sample table (Property)",
77+
"synced_property_id": "VQ}{"
78+
}
7679
}
7780
},
7881
"Name": {

Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
"type": "relation",
7272
"relation": {
7373
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
74-
"synced_property_name": "Related to sample table (Property)",
75-
"synced_property_id": "VQ}{"
74+
"type": "dual_property",
75+
"dual_property": {
76+
"synced_property_name": "Related to sample table (Property)",
77+
"synced_property_id": "VQ}{"
78+
}
7679
}
7780
},
7881
"Name": {

Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@
8282
"type": "relation",
8383
"relation": {
8484
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
85-
"synced_property_name": "Related to sample table (Property)",
86-
"synced_property_id": "VQ}{"
85+
"type": "dual_property",
86+
"dual_property": {
87+
"synced_property_name": "Related to sample table (Property)",
88+
"synced_property_id": "VQ}{"
89+
}
8790
}
8891
},
8992
"Name": {

Test/Notion.UnitTests/data/databases/DatabasesListResponse.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@
7474
"type": "relation",
7575
"relation": {
7676
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
77-
"synced_property_name": "Related to sample table (Property)",
78-
"synced_property_id": "VQ}{"
77+
"type": "dual_property",
78+
"dual_property": {
79+
"synced_property_name": "Related to sample table (Property)",
80+
"synced_property_id": "VQ}{"
81+
}
7982
}
8083
},
8184
"Name": {
@@ -188,8 +191,11 @@
188191
"type": "relation",
189192
"relation": {
190193
"database_id": "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1",
191-
"synced_property_name": "Property",
192-
"synced_property_id": "zDGa"
194+
"type": "dual_property",
195+
"dual_property": {
196+
"synced_property_name": "Property",
197+
"synced_property_id": "zDGa"
198+
}
193199
}
194200
},
195201
"Column 1": {

0 commit comments

Comments
 (0)
0