From b3f859134b4e5f82a2739bbcd4db8c9e18d923fc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:09:52 +0530 Subject: [PATCH 1/2] Add support to pagination query params to List Users --- Src/Notion.Client/Api/Users/IUsersClient.cs | 6 ++++ .../Users/List/Request/ListUsersParameters.cs | 13 ++++++++ .../Api/Users/List/UsersClient.cs | 30 +++++++++++++++++++ Src/Notion.Client/Api/Users/UsersClient.cs | 2 +- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs create mode 100644 Src/Notion.Client/Api/Users/List/UsersClient.cs diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index dc86ce12..0f9f18ac 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -1,5 +1,6 @@ using System.Threading; using System.Threading.Tasks; +using Notion.Client.List.Request; namespace Notion.Client { @@ -23,6 +24,11 @@ public interface IUsersClient /// Task> ListAsync(CancellationToken cancellationToken = default); + Task> ListAsync( + ListUsersParameters listUsersParameters, + CancellationToken cancellationToken = default + ); + /// /// Retrieves the bot User associated with the API token provided in the authorization header. /// diff --git a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs b/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs new file mode 100644 index 00000000..046a0c5b --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs @@ -0,0 +1,13 @@ +namespace Notion.Client.List.Request +{ + public interface IListUsersQueryParameters : IPaginationParameters + { + } + + public class ListUsersParameters : IListUsersQueryParameters + { + public string StartCursor { get; set; } + + public int? PageSize { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Users/List/UsersClient.cs b/Src/Notion.Client/Api/Users/List/UsersClient.cs new file mode 100644 index 00000000..57c40ea3 --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/UsersClient.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Notion.Client.List.Request; + +namespace Notion.Client +{ + public partial class UsersClient + { + public async Task> ListAsync( + ListUsersParameters listUsersParameters, + CancellationToken cancellationToken = default + ) + { + var queryParameters = (IListUsersQueryParameters)listUsersParameters; + + var queryParams = new Dictionary + { + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } + }; + + return await _client.GetAsync>( + ApiEndpoints.UsersApiUrls.List(), + queryParams, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 66c18d3d..f40299ee 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class UsersClient : IUsersClient + public partial class UsersClient : IUsersClient { private readonly IRestClient _client; From 2c2b9f3404497fef17ca7cd5a8d18d882932ba44 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:10:20 +0530 Subject: [PATCH 2/2] Run dotnet format --- .../Models/Database/Properties/PropertyType.cs | 2 +- .../Database/Properties/UniqueIdProperty.cs | 5 ++--- .../PropertyValue/UniqueIdPropertyValue.cs | 3 +-- .../IBlocksClientTests.cs | 16 ++++++++-------- Test/Notion.IntegrationTests/IPageClientTests.cs | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index 1d53b2a8..6391308c 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -70,6 +70,6 @@ public enum PropertyType Status, [EnumMember(Value = "unique_id")] - UniqueId, + UniqueId, } } diff --git a/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs index 8b56b462..4a9e9d5d 100644 --- a/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client -{ +{ public class UniqueIdProperty : Property { public override PropertyType Type => PropertyType.UniqueId; diff --git a/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs index 716d9cce..0ce1c704 100644 --- a/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 6f10189c..3f616cfa 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -211,7 +211,7 @@ private static IEnumerable BlockData() new Action((block, client) => { block.Should().NotBeNull(); - + block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); @@ -252,7 +252,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); - + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); }) }, @@ -282,7 +282,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); - + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); }) }, @@ -314,7 +314,7 @@ private static IEnumerable BlockData() Assert.NotNull(block); var imageBlock = Assert.IsType(block); var imageFile = Assert.IsType(imageBlock.Image); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); }) @@ -339,7 +339,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var embedBlock = Assert.IsType(block); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); }) @@ -381,10 +381,10 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var templateBlock = Assert.IsType(block); - + Assert.Single(templateBlock.Template.RichText); Assert.Null(templateBlock.Template.Children); - + Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); }) @@ -407,7 +407,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var linkToPageBlock = Assert.IsType(block); - + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); // TODO: Currently the api doesn't allow to update the link_to_page block type diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index f0833be5..84ac493e 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -330,11 +330,11 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin }; var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePageRequest); - + // Assert page.Properties["Colors1"].As().Select.Name.Should().Be("Red"); page.Properties["Colors2"].As().Select.Name.Should().Be("Green"); - + updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); updatedPage.Properties["Colors2"].As().Select.Should().BeNull();