Skip to content

Commit 0d3f322

Browse files
Add block property in Append children api response
1 parent e66a83f commit 0d3f322

File tree

9 files changed

+72
-38
lines changed

9 files changed

+72
-38
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: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ public BlocksClient(IRestClient client)
1515
_client = client;
1616
}
1717

18-
public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
19-
string blockId,
20-
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default)
21-
{
22-
if (string.IsNullOrWhiteSpace(blockId))
23-
{
24-
throw new ArgumentNullException(nameof(blockId));
25-
}
26-
27-
var url = BlocksApiUrls.AppendChildren(blockId);
28-
29-
var body = (IBlocksAppendChildrenBodyParameters)parameters;
30-
31-
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body, cancellationToken: cancellationToken);
32-
}
33-
3418
public async Task<IBlock> RetrieveAsync(string blockId, CancellationToken cancellationToken = default)
3519
{
3620
if (string.IsNullOrWhiteSpace(blockId))

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ Task<RetrieveChildrenResponse> RetrieveChildrenAsync(
3838
/// <summary>
3939
/// Creates and appends new children blocks to the parent block_id specified.
4040
/// </summary>
41-
/// <param name="blockId">Identifier for a block</param>
42-
/// <param name="parameters"></param>
41+
/// <param name="request"></param>
42+
/// <param name="cancellationToken"></param>
4343
/// <returns>A paginated list of newly created first level children block objects.</returns>
44-
Task<PaginatedList<IBlock>> AppendChildrenAsync(
45-
string blockId,
46-
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default);
44+
Task<AppendChildrenResponse> AppendChildrenAsync(
45+
BlockAppendChildrenRequest request,
46+
CancellationToken cancellationToken = default
47+
);
4748

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

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
2020
);
2121

2222
var blocks = await Client.Blocks.AppendChildrenAsync(
23-
page.Id,
24-
new BlocksAppendChildrenParameters
23+
new BlockAppendChildrenRequest
2524
{
25+
BlockId = page.Id,
2626
Children = new List<IBlock>
2727
{
2828
new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() },
@@ -58,21 +58,21 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock()
5858
);
5959

6060
var blocks = await Client.Blocks.AppendChildrenAsync(
61-
page.Id,
62-
new BlocksAppendChildrenParameters
61+
new BlockAppendChildrenRequest
6362
{
63+
BlockId = page.Id,
6464
Children = new List<IBlock> { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } }
6565
}
6666
);
6767

6868
var blockId = blocks.Results.First().Id;
6969
await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock());
7070

71-
blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest
71+
var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest
7272
{
7373
BlockId = page.Id
7474
});
75-
blocks.Results.Should().HaveCount(1);
75+
updatedBlocks.Results.Should().HaveCount(1);
7676

7777
// cleanup
7878
await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true });
@@ -88,9 +88,9 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
8888
);
8989

9090
var blocks = await Client.Blocks.AppendChildrenAsync(
91-
page.Id,
92-
new BlocksAppendChildrenParameters
91+
new BlockAppendChildrenRequest
9392
{
93+
BlockId = page.Id,
9494
Children = new List<IBlock>
9595
{
9696
new DividerBlock { Divider = new DividerBlock.Data() },
@@ -117,20 +117,23 @@ public async Task UpdateAsync_UpdatesGivenBlock(
117117
);
118118

119119
var blocks = await Client.Blocks.AppendChildrenAsync(
120-
page.Id,
121-
new BlocksAppendChildrenParameters { Children = new List<IBlock> { block } }
120+
new BlockAppendChildrenRequest
121+
{
122+
BlockId = page.Id,
123+
Children = new List<IBlock> { block }
124+
}
122125
);
123126

124127
var blockId = blocks.Results.First().Id;
125128
await Client.Blocks.UpdateAsync(blockId, updateBlock);
126129

127-
blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest
130+
var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest
128131
{
129132
BlockId = page.Id
130133
});
131-
blocks.Results.Should().HaveCount(1);
134+
updatedBlocks.Results.Should().HaveCount(1);
132135

133-
var updatedBlock = blocks.Results.First();
136+
var updatedBlock = updatedBlocks.Results.First();
134137

135138
assert.Invoke(updatedBlock, Client);
136139

Test/Notion.UnitTests/BlocksClientTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ public async Task AppendBlockChildren()
6060
.WithBody(jsonData)
6161
);
6262

63-
var parameters = new BlocksAppendChildrenParameters
63+
var request = new BlockAppendChildrenRequest
6464
{
65+
BlockId = blockId,
6566
Children = new List<IBlock>
6667
{
6768
new HeadingTwoBlock
@@ -100,7 +101,7 @@ public async Task AppendBlockChildren()
100101
};
101102

102103
// Act
103-
var blocksResult = await _client.AppendChildrenAsync(blockId, parameters);
104+
var blocksResult = await _client.AppendChildrenAsync(request);
104105

105106
// Assert
106107
var blocks = blocksResult.Results;

0 commit comments

Comments
 (0)