Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support to pagination query params to List Users
  • Loading branch information
KoditkarVedant committed Sep 16, 2023
commit b3f859134b4e5f82a2739bbcd4db8c9e18d923fc
6 changes: 6 additions & 0 deletions Src/Notion.Client/Api/Users/IUsersClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using Notion.Client.List.Request;

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

Task<PaginatedList<User>> ListAsync(
ListUsersParameters listUsersParameters,
CancellationToken cancellationToken = default
);

/// <summary>
/// Retrieves the bot User associated with the API token provided in the authorization header.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
30 changes: 30 additions & 0 deletions Src/Notion.Client/Api/Users/List/UsersClient.cs
Original file line number Diff line number Diff line change
@@ -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<PaginatedList<User>> ListAsync(
ListUsersParameters listUsersParameters,
CancellationToken cancellationToken = default
)
{
var queryParameters = (IListUsersQueryParameters)listUsersParameters;

var queryParams = new Dictionary<string, string>
{
{ "start_cursor", queryParameters?.StartCursor },
{ "page_size", queryParameters?.PageSize?.ToString() }
};

return await _client.GetAsync<PaginatedList<User>>(
ApiEndpoints.UsersApiUrls.List(),
queryParams,
cancellationToken: cancellationToken
);
}
}
}
2 changes: 1 addition & 1 deletion Src/Notion.Client/Api/Users/UsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Notion.Client
{
public class UsersClient : IUsersClient
public partial class UsersClient : IUsersClient
{
private readonly IRestClient _client;

Expand Down