From 609e04dc8b9ef3969d3c214af95e5ddaf18e8b13 Mon Sep 17 00:00:00 2001 From: kosaku-hayashi Date: Sun, 14 Jul 2024 17:01:31 +0900 Subject: [PATCH] Added support for button properties. --- .../Database/Properties/ButtonProperty.cs | 16 ++++++++++++++++ .../Models/Database/Properties/Property.cs | 1 + .../Models/Database/Properties/PropertyType.cs | 3 +++ .../Models/PropertyValue/ButtonPropertyValue.cs | 17 +++++++++++++++++ .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 3 +++ Test/Notion.UnitTests/PagesClientTests.cs | 2 +- Test/Notion.UnitTests/PropertyTests.cs | 2 ++ .../databases/DatabaseRetrieveResponse.json | 6 ++++++ .../data/databases/DatabasesListResponse.json | 6 ++++++ .../data/databases/DatabasesQueryResponse.json | 5 +++++ .../data/pages/TrashPageResponse.json | 5 +++++ 12 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs create mode 100644 Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs diff --git a/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs b/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs new file mode 100644 index 00000000..983138e2 --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public class ButtonProperty : Property + { + public override PropertyType Type => PropertyType.Button; + + [JsonProperty("button")] + public Dictionary Button { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index fa0dac50..6392bbaf 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -26,6 +26,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonProperty), PropertyType.Button)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index 6391308c..206f9fe2 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -71,5 +71,8 @@ public enum PropertyType [EnumMember(Value = "unique_id")] UniqueId, + + [EnumMember(Value = "button")] + Button, } } diff --git a/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs new file mode 100644 index 00000000..61ae9fc4 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ButtonPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.Button; + + [JsonProperty("button")] + public ButtonValue Button { get; set; } + + public class ButtonValue { } + } +} diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index a74b11da..e1289046 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -30,6 +30,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonPropertyValue), PropertyValueType.Button)] [JsonSubtypes.KnownSubTypeAttribute(typeof(VerificationPropertyValue), PropertyValueType.Verification)] [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index d77a564c..574138e9 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -77,5 +77,8 @@ public enum PropertyValueType [EnumMember(Value = "verification")] Verification, + + [EnumMember(Value = "button")] + Button, } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 9541f62e..4dc75380 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -222,7 +222,7 @@ public async Task TrashPageAsync() page.Id.Should().Be(pageId); page.InTrash.Should().BeTrue(); - page.Properties.Should().HaveCount(2); + page.Properties.Should().HaveCount(3); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync( diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index fc748413..55f6d1c1 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -27,6 +27,7 @@ public class PropertyTests [InlineData(typeof(TitleProperty), PropertyType.Title)] [InlineData(typeof(UrlProperty), PropertyType.Url)] [InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)] + [InlineData(typeof(ButtonProperty),PropertyType.Button)] public void TestPropertyType(Type type, PropertyType expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); @@ -56,6 +57,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType) [InlineData(typeof(TitleProperty), "title")] [InlineData(typeof(UrlProperty), "url")] [InlineData(typeof(UniqueIdProperty), "unique_id")] + [InlineData(typeof(ButtonProperty), "button")] public void TestPropertyTypeText(Type type, string expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); diff --git a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json index 5849bb88..9e1acfb0 100644 --- a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json @@ -90,6 +90,12 @@ } } }, + "SimpleButton": { + "id":"_ri%7C", + "name":"SimpleButton", + "type":"button", + "button": {} + }, "Name": { "id": "title", "name": "Name", diff --git a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json index 713c0736..ad0e5497 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json @@ -81,6 +81,12 @@ } } }, + "SimpleButton": { + "id":"_ri%7C", + "name":"SimpleButton", + "type":"button", + "button": {} + }, "Name": { "id": "title", "name": "Name", diff --git a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json index cf1b1f01..d291a5b2 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json @@ -45,6 +45,11 @@ "id": "{>U;", "type": "checkbox", "checkbox": false + }, + "Add Page Button": { + "id":"_ri%7C", + "type":"button", + "button": {} } } } diff --git a/Test/Notion.UnitTests/data/pages/TrashPageResponse.json b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json index 0c61a3c9..add1f546 100644 --- a/Test/Notion.UnitTests/data/pages/TrashPageResponse.json +++ b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json @@ -11,6 +11,11 @@ "type": "checkbox", "checkbox": true }, + "Add Page Button": { + "id":"_ri%7C", + "type":"button", + "button": {} + }, "Name": { "id": "title", "type": "title",