Skip to content

Commit 9167516

Browse files
Merge pull request #395 from notion-dotnet/feature/394-add-type-specific-pagination-information
Add type specific pagination information
2 parents b2d5708 + 535b161 commit 9167516

32 files changed

+243
-105
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
namespace Notion.Client
6+
{
7+
public sealed partial class BlocksClient
8+
{
9+
public async Task<AppendChildrenResponse> AppendChildrenAsync(
10+
BlockAppendChildrenRequest request,
11+
CancellationToken cancellationToken = default)
12+
{
13+
if (string.IsNullOrWhiteSpace(request.BlockId))
14+
{
15+
throw new ArgumentNullException(nameof(request.BlockId));
16+
}
17+
18+
var url = ApiEndpoints.BlocksApiUrls.AppendChildren(request.BlockId);
19+
20+
var body = (IBlockAppendChildrenBodyParameters)request;
21+
22+
return await _client.PatchAsync<AppendChildrenResponse>(url, body, cancellationToken: cancellationToken);
23+
}
24+
}
25+
}

Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs renamed to Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Notion.Client
44
{
5-
public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters
5+
public class BlockAppendChildrenRequest : IBlockAppendChildrenBodyParameters, IBlockAppendChildrenPathParameters
66
{
77
public IEnumerable<IBlock> Children { get; set; }
88

99
public string After { get; set; }
10+
11+
public string BlockId { get; set; }
1012
}
1113
}

Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs renamed to Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Notion.Client
55
{
66
// TODO: need an input version of Block
7-
public interface IBlocksAppendChildrenBodyParameters
7+
public interface IBlockAppendChildrenBodyParameters
88
{
99
[JsonProperty("children")]
1010
IEnumerable<IBlock> Children { get; set; }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Notion.Client
2+
{
3+
public interface IBlockAppendChildrenPathParameters
4+
{
5+
public string BlockId { get; set; }
6+
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class AppendChildrenResponse : PaginatedList<IBlock>
7+
{
8+
[JsonProperty("block")]
9+
public Dictionary<string, object> Block { get; set; }
10+
}
11+
}

Src/Notion.Client/Api/Blocks/BlocksClient.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Notion.Client
88
{
9-
public class BlocksClient : IBlocksClient
9+
public sealed partial class BlocksClient : IBlocksClient
1010
{
1111
private readonly IRestClient _client;
1212

@@ -15,44 +15,6 @@ public BlocksClient(IRestClient client)
1515
_client = client;
1616
}
1717

18-
public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
19-
string blockId,
20-
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default)
21-
{
22-
if (string.IsNullOrWhiteSpace(blockId))
23-
{
24-
throw new ArgumentNullException(nameof(blockId));
25-
}
26-
27-
var url = BlocksApiUrls.RetrieveChildren(blockId);
28-
29-
var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters;
30-
31-
var queryParams = new Dictionary<string, string>
32-
{
33-
{ "start_cursor", queryParameters?.StartCursor },
34-
{ "page_size", queryParameters?.PageSize?.ToString() }
35-
};
36-
37-
return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams, cancellationToken: cancellationToken);
38-
}
39-
40-
public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
41-
string blockId,
42-
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default)
43-
{
44-
if (string.IsNullOrWhiteSpace(blockId))
45-
{
46-
throw new ArgumentNullException(nameof(blockId));
47-
}
48-
49-
var url = BlocksApiUrls.AppendChildren(blockId);
50-
51-
var body = (IBlocksAppendChildrenBodyParameters)parameters;
52-
53-
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body, cancellationToken: cancellationToken);
54-
}
55-
5618
public async Task<IBlock> RetrieveAsync(string blockId, CancellationToken cancellationToken = default)
5719
{
5820
if (string.IsNullOrWhiteSpace(blockId))

Src/Notion.Client/Api/Blocks/IBlocksClient.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@ public interface IBlocksClient
1818
/// <param name="blockId"></param>
1919
/// <param name="updateBlock"></param>
2020
/// <returns>Block</returns>
21-
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default);
21+
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock,
22+
CancellationToken cancellationToken = default);
2223

23-
Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
24-
string blockId,
25-
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default);
24+
/// <summary>
25+
/// Returns a paginated array of child block objects contained in the block using the ID specified.
26+
/// <br/>
27+
/// In order to receive a complete representation of a block, you may need to recursively retrieve the
28+
/// block children of child blocks.
29+
/// </summary>
30+
/// <param name="request"></param>
31+
/// <param name="cancellationToken"></param>
32+
/// <returns></returns>
33+
Task<RetrieveChildrenResponse> RetrieveChildrenAsync(
34+
BlockRetrieveChildrenRequest request,
35+
CancellationToken cancellationToken = default
36+
);
2637

2738
/// <summary>
2839
/// Creates and appends new children blocks to the parent block_id specified.
2940
/// </summary>
30-
/// <param name="blockId">Identifier for a block</param>
31-
/// <param name="parameters"></param>
41+
/// <param name="request"></param>
42+
/// <param name="cancellationToken"></param>
3243
/// <returns>A paginated list of newly created first level children block objects.</returns>
33-
Task<PaginatedList<IBlock>> AppendChildrenAsync(
34-
string blockId,
35-
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default);
44+
Task<AppendChildrenResponse> AppendChildrenAsync(
45+
BlockAppendChildrenRequest request,
46+
CancellationToken cancellationToken = default
47+
);
3648

3749
/// <summary>
3850
/// Sets a Block object, including page blocks, to archived: true using the ID specified.

Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace Notion.Client
7+
{
8+
public sealed partial class BlocksClient
9+
{
10+
public async Task<RetrieveChildrenResponse> RetrieveChildrenAsync(
11+
BlockRetrieveChildrenRequest request,
12+
CancellationToken cancellationToken = default)
13+
{
14+
if (string.IsNullOrWhiteSpace(request.BlockId))
15+
{
16+
throw new ArgumentNullException(nameof(request.BlockId));
17+
}
18+
19+
var url = ApiEndpoints.BlocksApiUrls.RetrieveChildren(request.BlockId);
20+
21+
var queryParameters = (IBlockRetrieveChildrenQueryParameters)request;
22+
23+
var queryParams = new Dictionary<string, string>
24+
{
25+
{ "start_cursor", queryParameters?.StartCursor },
26+
{ "page_size", queryParameters?.PageSize?.ToString() }
27+
};
28+
29+
return await _client.GetAsync<RetrieveChildrenResponse>(
30+
url,
31+
queryParams,
32+
cancellationToken: cancellationToken
33+
);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)