From b261ba96aace4b49fdef222abcbb28e9567ec3ab Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 15 Jul 2022 23:14:56 +0530 Subject: [PATCH 1/6] add timezone support to date property --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 6182b197..cc0818ae 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -33,5 +33,11 @@ public class Date /// [JsonProperty("end")] public DateTime? End { get; set; } + + /// + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// + [JsonProperty("time_zone")] + public string TimeZone { get; set; } } } From ca5d611b919d76b6dec31a42183320a99f0bd1f1 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 15 Jul 2022 23:48:21 +0530 Subject: [PATCH 2/6] add caption property in code block --- .../BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs | 3 +++ Src/Notion.Client/Models/Blocks/CodeBlock.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs index 1364adb0..e6b26fad 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs @@ -15,6 +15,9 @@ public class Info [JsonProperty("language")] public string Language { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 7eb4205d..f00905f7 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -17,6 +17,9 @@ public class Info [JsonProperty("language")] public string Language { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } } From e57a2d7649284a945b63d883419a21292cd2de3d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 18:37:09 +0530 Subject: [PATCH 3/6] =?UTF-8?q?add=20ability=20to=20clear=20date=20propert?= =?UTF-8?q?y=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index cc0818ae..aeb3cd8e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -13,7 +13,7 @@ public class DatePropertyValue : PropertyValue /// /// Date /// - [JsonProperty("date")] + [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } From 2e9767c5a6daadf8fd5c8a2072c360fc456bb509 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 18:37:34 +0530 Subject: [PATCH 4/6] =?UTF-8?q?Add=20&=20refactor=20test=20cases=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IPageClientTests.cs | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index ae1e317b..a2c73162 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -11,6 +11,7 @@ namespace Notion.IntegrationTests public class IPageClientTests { private readonly INotionClient _client; + private readonly string _databaseId; public IPageClientTests() { @@ -20,6 +21,7 @@ public IPageClientTests() }; _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; } [Fact] @@ -27,7 +29,7 @@ public async Task CreateAsync_CreatesANewPage() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -48,7 +50,7 @@ public async Task CreateAsync_CreatesANewPage() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -65,7 +67,7 @@ public async Task Bug_unable_to_create_page_with_select_property() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -93,7 +95,7 @@ public async Task Bug_unable_to_create_page_with_select_property() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -110,7 +112,7 @@ public async Task Test_RetrievePagePropertyItemAsync() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -155,5 +157,70 @@ public async Task Test_RetrievePagePropertyItemAsync() Archived = true }); } + + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date + + string datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + updateDatabaseParameters.Properties = new Dictionary + { + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } + }; + + PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput + { + DatabaseId = _databaseId + }) + .AddProperty("Name", new TitlePropertyValue + { + Title = new List + { + new RichTextText + { + Text = new Text + { + Content = "Test Page Title" + } + } + } + }) + .AddProperty(datePropertyName, new DatePropertyValue + { + Date = new Date() + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z") + } + }) + .Build(); + + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + + var page = await _client.Pages.CreateAsync(pagesCreateParameters); + + var setDate = page.Properties[datePropertyName] as DatePropertyValue; + + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + { + Properties = testProps + }); + + var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue; + + verifyDate?.Date.Should().BeNull(); + + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } } } From d60b7421ae5c180a70b7d6006c4fa540b6d2976f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 19:11:59 +0530 Subject: [PATCH 5/6] Add support for Table and TableRow block --- .../UpdateBlocks/TableRowUpdateBlock.cs | 17 ++++++++++++ .../UpdateBlocks/TableUpdateBlock.cs | 19 +++++++++++++ Src/Notion.Client/Models/Blocks/BlockType.cs | 6 +++++ Src/Notion.Client/Models/Blocks/IBlock.cs | 2 ++ Src/Notion.Client/Models/Blocks/TableBlock.cs | 27 +++++++++++++++++++ .../Models/Blocks/TableRowBlock.cs | 19 +++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/TableBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/TableRowBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs new file mode 100644 index 00000000..be422530 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("table_row")] + public Info TableRow { get; set; } + + public class Info + { + [JsonProperty("cells")] + public IEnumerable> Cells { get; set; } + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs new file mode 100644 index 00000000..6079e27b --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("table")] + public Info Table { get; set; } + + public class Info + { + [JsonProperty("has_column_header")] + public bool HasColumnHeader { get; set; } + + [JsonProperty("has_row_header")] + public bool HasRowHeader { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 6ebec8f1..f3181b22 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -91,6 +91,12 @@ public enum BlockType [EnumMember(Value = "synced_block")] SyncedBlock, + [EnumMember(Value = "table")] + Table, + + [EnumMember(Value = "table_row")] + TableRow, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a7e925d1..f3c89d88 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -28,6 +28,8 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs new file mode 100644 index 00000000..e9f716df --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.Table; + + [JsonProperty("table")] + public TableInfo Table { get; set; } + + public class TableInfo + { + [JsonProperty("table_width")] + public int TableWidth { get; set; } + + [JsonProperty("has_column_header")] + public bool HasColumnHeader { get; set; } + + [JsonProperty("has_row_header")] + public bool HasRowHeader { get; set; } + + [JsonProperty("children")] + public TableRowBlock Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs new file mode 100644 index 00000000..978e7d8c --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.TableRow; + + [JsonProperty("table_row")] + public Info TableRow { get; set; } + + public class Info + { + [JsonProperty("cells")] + public IEnumerable> Cells { get; set; } + } + } +} From f739b99ce5dac9e24acd62fa9921fa176283af2f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 19:19:03 +0530 Subject: [PATCH 6/6] =?UTF-8?q?Run=20linter=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs | 2 +- .../BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/TableRowBlock.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs index be422530..c228de66 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs index 6079e27b..ef0e8933 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index e9f716df..dd20d94b 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index 978e7d8c..e7214e6c 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client