Skip to content

Commit 062b1fd

Browse files
Merge pull request #376 from notion-dotnet/358-support-passing-query-params-to-list-users-api
Add support for query params to list users API
2 parents feec5eb + 2c2b9f3 commit 062b1fd

File tree

9 files changed

+64
-17
lines changed

9 files changed

+64
-17
lines changed

Src/Notion.Client/Api/Users/IUsersClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Threading;
22
using System.Threading.Tasks;
3+
using Notion.Client.List.Request;
34

45
namespace Notion.Client
56
{
@@ -23,6 +24,11 @@ public interface IUsersClient
2324
/// </returns>
2425
Task<PaginatedList<User>> ListAsync(CancellationToken cancellationToken = default);
2526

27+
Task<PaginatedList<User>> ListAsync(
28+
ListUsersParameters listUsersParameters,
29+
CancellationToken cancellationToken = default
30+
);
31+
2632
/// <summary>
2733
/// Retrieves the bot User associated with the API token provided in the authorization header.
2834
/// </summary>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Notion.Client.List.Request
2+
{
3+
public interface IListUsersQueryParameters : IPaginationParameters
4+
{
5+
}
6+
7+
public class ListUsersParameters : IListUsersQueryParameters
8+
{
9+
public string StartCursor { get; set; }
10+
11+
public int? PageSize { get; set; }
12+
}
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Notion.Client.List.Request;
5+
6+
namespace Notion.Client
7+
{
8+
public partial class UsersClient
9+
{
10+
public async Task<PaginatedList<User>> ListAsync(
11+
ListUsersParameters listUsersParameters,
12+
CancellationToken cancellationToken = default
13+
)
14+
{
15+
var queryParameters = (IListUsersQueryParameters)listUsersParameters;
16+
17+
var queryParams = new Dictionary<string, string>
18+
{
19+
{ "start_cursor", queryParameters?.StartCursor },
20+
{ "page_size", queryParameters?.PageSize?.ToString() }
21+
};
22+
23+
return await _client.GetAsync<PaginatedList<User>>(
24+
ApiEndpoints.UsersApiUrls.List(),
25+
queryParams,
26+
cancellationToken: cancellationToken
27+
);
28+
}
29+
}
30+
}

Src/Notion.Client/Api/Users/UsersClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Notion.Client
66
{
7-
public class UsersClient : IUsersClient
7+
public partial class UsersClient : IUsersClient
88
{
99
private readonly IRestClient _client;
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public enum PropertyType
7070
Status,
7171

7272
[EnumMember(Value = "unique_id")]
73-
UniqueId,
73+
UniqueId,
7474
}
7575
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using Newtonsoft.Json;
43

54
namespace Notion.Client
6-
{
5+
{
76
public class UniqueIdProperty : Property
87
{
98
public override PropertyType Type => PropertyType.UniqueId;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32

43
namespace Notion.Client
54
{

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static IEnumerable<object[]> BlockData()
211211
new Action<IBlock, INotionClient>((block, client) =>
212212
{
213213
block.Should().NotBeNull();
214-
214+
215215
block.Should().BeOfType<AudioBlock>().Subject
216216
.Audio.Should().BeOfType<ExternalFile>().Subject
217217
.External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3");
@@ -252,7 +252,7 @@ private static IEnumerable<object[]> BlockData()
252252
{
253253
Assert.NotNull(block);
254254
var calloutBlock = Assert.IsType<CalloutBlock>(block);
255-
255+
256256
Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType<RichTextText>().First().Text.Content);
257257
})
258258
},
@@ -282,7 +282,7 @@ private static IEnumerable<object[]> BlockData()
282282
{
283283
Assert.NotNull(block);
284284
var quoteBlock = Assert.IsType<QuoteBlock>(block);
285-
285+
286286
Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType<RichTextText>().First().Text.Content);
287287
})
288288
},
@@ -314,7 +314,7 @@ private static IEnumerable<object[]> BlockData()
314314
Assert.NotNull(block);
315315
var imageBlock = Assert.IsType<ImageBlock>(block);
316316
var imageFile = Assert.IsType<ExternalFile>(imageBlock.Image);
317-
317+
318318
Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg",
319319
imageFile.External.Url);
320320
})
@@ -339,7 +339,7 @@ private static IEnumerable<object[]> BlockData()
339339
{
340340
Assert.NotNull(block);
341341
var embedBlock = Assert.IsType<EmbedBlock>(block);
342-
342+
343343
Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg",
344344
embedBlock.Embed.Url);
345345
})
@@ -381,10 +381,10 @@ private static IEnumerable<object[]> BlockData()
381381
{
382382
Assert.NotNull(block);
383383
var templateBlock = Assert.IsType<TemplateBlock>(block);
384-
384+
385385
Assert.Single(templateBlock.Template.RichText);
386386
Assert.Null(templateBlock.Template.Children);
387-
387+
388388
Assert.Equal("Test Template 2",
389389
templateBlock.Template.RichText.OfType<RichTextText>().First().Text.Content);
390390
})
@@ -407,7 +407,7 @@ private static IEnumerable<object[]> BlockData()
407407
{
408408
Assert.NotNull(block);
409409
var linkToPageBlock = Assert.IsType<LinkToPageBlock>(block);
410-
410+
411411
var pageParent = Assert.IsType<PageParent>(linkToPageBlock.LinkToPage);
412412

413413
// TODO: Currently the api doesn't allow to update the link_to_page block type

Test/Notion.IntegrationTests/IPageClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin
330330
};
331331

332332
var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePageRequest);
333-
333+
334334
// Assert
335335
page.Properties["Colors1"].As<SelectPropertyValue>().Select.Name.Should().Be("Red");
336336
page.Properties["Colors2"].As<SelectPropertyValue>().Select.Name.Should().Be("Green");
337-
337+
338338
updatedPage.Properties["Colors1"].As<SelectPropertyValue>().Select.Name.Should().Be("Blue");
339339
updatedPage.Properties["Colors2"].As<SelectPropertyValue>().Select.Should().BeNull();
340340

0 commit comments

Comments
 (0)