From 08c8ddb5e87a459b4f0d4c8271404c10be62d7ab Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 14:21:54 +0530 Subject: [PATCH 1/2] Add support to read Status property value --- .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 5 +- .../PropertyValue/StatusPropertyValue.cs | 72 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index c85ebbdc..8437b4f8 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -25,6 +25,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index 4a4b8189..fcbeae61 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -65,6 +65,9 @@ public enum PropertyValueType LastEditedTime, [EnumMember(Value = "last_edited_by")] - LastEditedBy + LastEditedBy, + + [EnumMember(Value = "status")] + Status, } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs new file mode 100644 index 00000000..f2027fef --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -0,0 +1,72 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + /// + /// Status property value objects contain page status + /// + public class StatusPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + } + + public enum Color + { + [EnumMember(Value = "default")] + Default, + + [EnumMember(Value = "gray")] + Gray, + + [EnumMember(Value = "brown")] + Brown, + + [EnumMember(Value = "orange")] + Orange, + + [EnumMember(Value = "yellow")] + Yellow, + + [EnumMember(Value = "green")] + Green, + + [EnumMember(Value = "blue")] + Blue, + + [EnumMember(Value = "purple")] + Purple, + + [EnumMember(Value = "pink")] + Pink, + + [EnumMember(Value = "red")] + Red, + } + } +} From 3e1479322ce6292d04fab29bcd6d642a6731b114 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 14:24:56 +0530 Subject: [PATCH 2/2] Add readonly Status property --- .../Models/Database/Properties/Property.cs | 1 + .../Models/Database/Properties/PropertyType.cs | 5 ++++- .../Models/Database/Properties/StatusProperty.cs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Database/Properties/StatusProperty.cs diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 30ecd151..1f61b0dc 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -22,6 +22,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] public class Property diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index bbc9eba7..a67b8cd8 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -62,6 +62,9 @@ public enum PropertyType LastEditedBy, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, + + [EnumMember(Value = "status")] + Status, } } diff --git a/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs b/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs new file mode 100644 index 00000000..92ec46fd --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class StatusProperty : Property + { + public override PropertyType Type => PropertyType.Status; + + [JsonProperty("status")] + public Dictionary Status { get; set; } + } +}