Skip to content

Commit 807a538

Browse files
Add support to create a comment
1 parent c43475a commit 807a538

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public static class SearchApiUrls
6565
public static class CommentsApiUrls
6666
{
6767
public static string Retrieve() => "/v1/comments";
68+
69+
public static string Create() => "/v1/comments";
6870
}
6971
}
7072
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Notion.Client
4+
{
5+
public partial class CommentsClient
6+
{
7+
public async Task<CreateCommentResponse> Create(CreateCommentParameters parameters)
8+
{
9+
var body = (ICreateCommentsBodyParameters)parameters;
10+
11+
return await _client.PostAsync<CreateCommentResponse>(
12+
ApiEndpoints.CommentsApiUrls.Create(),
13+
body
14+
);
15+
}
16+
}
17+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public interface ICreateCommentsBodyParameters
7+
{
8+
[JsonProperty("rich_text")]
9+
public IEnumerable<RichTextBaseInput> RichText { get; set; }
10+
}
11+
12+
public interface ICreateDiscussionCommentBodyParameters : ICreateCommentsBodyParameters
13+
{
14+
[JsonProperty("discussion_id")]
15+
public string DiscussionId { get; set; }
16+
}
17+
18+
public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameters
19+
{
20+
[JsonProperty("parent")]
21+
public ParentPageInput Parent { get; set; }
22+
}
23+
24+
public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters
25+
{
26+
public string DiscussionId { get; set; }
27+
public IEnumerable<RichTextBaseInput> RichText { get; set; }
28+
public ParentPageInput Parent { get; set; }
29+
30+
public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable<RichTextBaseInput> richText)
31+
{
32+
return new CreateCommentParameters
33+
{
34+
Parent = parent,
35+
RichText = richText
36+
};
37+
}
38+
39+
public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable<RichTextBaseInput> richText)
40+
{
41+
return new CreateCommentParameters
42+
{
43+
DiscussionId = discussionId,
44+
RichText = richText
45+
};
46+
}
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Notion.Client
2+
{
3+
public class CreateCommentResponse : Comment
4+
{
5+
}
6+
}

Src/Notion.Client/Api/Comments/ICommentsClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public interface ICommentsClient
1010
/// <param name="retrieveCommentsParameters">Retrieve comments parameters</param>
1111
/// <returns><see cref="RetrieveCommentsResponse"/></returns>
1212
Task<RetrieveCommentsResponse> Retrieve(RetrieveCommentsParameters retrieveCommentsParameters);
13+
14+
Task<CreateCommentResponse> Create(CreateCommentParameters createCommentParameters);
1315
}
1416
}

0 commit comments

Comments
 (0)