Skip to content

Commit dd5a5ad

Browse files
Merge pull request #367 from RandomUser14/main
Add support to deserialize unique_id
2 parents 3c175c2 + a298ec8 commit dd5a5ad

File tree

7 files changed

+56
-2
lines changed

7 files changed

+56
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Notion.Client
2525
[JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)]
2626
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)]
2727
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)]
28+
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)]
2829
public class Property
2930
{
3031
[JsonProperty("id")]

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public enum PropertyType
6767
LastEditedTime,
6868

6969
[EnumMember(Value = "status")]
70-
Status
70+
Status,
71+
72+
[EnumMember(Value = "unique_id")]
73+
UniqueId,
7174
}
7275
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace Notion.Client
6+
{
7+
public class UniqueIdProperty : Property
8+
{
9+
public override PropertyType Type => PropertyType.UniqueId;
10+
11+
[JsonProperty("unique_id")]
12+
public Dictionary<string, object> UniqueId { get; set; }
13+
}
14+
}
15+

Src/Notion.Client/Models/PropertyValue/PropertyValue.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace Notion.Client
2929
[JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)]
3030
[JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)]
3131
[JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)]
32+
[JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)]
3233
[SuppressMessage("ReSharper", "UnusedMember.Global")]
3334
[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
3435
public class PropertyValue

Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public enum PropertyValueType
7070
LastEditedBy,
7171

7272
[EnumMember(Value = "status")]
73-
Status
73+
Status,
74+
75+
[EnumMember(Value = "unique_id")]
76+
UniqueId,
7477
}
7578
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
/// <summary>
7+
/// Unique Id property value object.
8+
/// </summary>
9+
public class UniqueIdPropertyValue : PropertyValue
10+
{
11+
public override PropertyValueType Type => PropertyValueType.UniqueId;
12+
13+
/// <summary>
14+
/// Unique Id property of database item
15+
/// </summary>
16+
[JsonProperty("unique_id")]
17+
public UniqueIdValue UniqueId { get; set; }
18+
}
19+
20+
public class UniqueIdValue
21+
{
22+
[JsonProperty("prefix")]
23+
public string Prefix { get; set; }
24+
25+
[JsonProperty("number")]
26+
public double? Number { get; set; }
27+
}
28+
}
29+

Test/Notion.UnitTests/PropertyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PropertyTests
2626
[InlineData(typeof(SelectProperty), PropertyType.Select)]
2727
[InlineData(typeof(TitleProperty), PropertyType.Title)]
2828
[InlineData(typeof(UrlProperty), PropertyType.Url)]
29+
[InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)]
2930
public void TestPropertyType(Type type, PropertyType expectedPropertyType)
3031
{
3132
var typeInstance = (Property)Activator.CreateInstance(type);
@@ -54,6 +55,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType)
5455
[InlineData(typeof(SelectProperty), "select")]
5556
[InlineData(typeof(TitleProperty), "title")]
5657
[InlineData(typeof(UrlProperty), "url")]
58+
[InlineData(typeof(UniqueIdProperty), "unique_id")]
5759
public void TestPropertyTypeText(Type type, string expectedPropertyType)
5860
{
5961
var typeInstance = (Property)Activator.CreateInstance(type);

0 commit comments

Comments
 (0)