Skip to content

Commit bf2ea89

Browse files
Merge pull request #97 from notion-dotnet/feature/56-add-support-for-create-new-databases-api
Add support for create new databases API 💖
2 parents 79cf106 + da74a17 commit bf2ea89

36 files changed

+446
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var complexFiler = new CompoundFilter(
9797
- [x] Retrieve a database
9898
- [x] Query a database
9999
- [x] List databases
100-
- [ ] Create a Database
100+
- [x] Create a Database
101101
- [x] Pages
102102
- [x] Retrieve a page
103103
- [x] Create a page

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class DatabasesApiUrls
77
public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}";
88
public static string List() => "/v1/databases";
99
public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query";
10+
public static string Create => "/v1/databases";
1011
}
1112

1213
public static class UsersApiUrls

Src/Notion.Client/Api/Databases/DatabasesClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ public async Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQu
3737

3838
return await _client.PostAsync<PaginatedList<Page>>(DatabasesApiUrls.Query(databaseId), body);
3939
}
40+
41+
public async Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters)
42+
{
43+
var body = (IDatabasesCreateBodyParameters)databasesCreateParameters;
44+
45+
return await _client.PostAsync<Database>(DatabasesApiUrls.Create, body);
46+
}
4047
}
4148
}

Src/Notion.Client/Api/Databases/IDatabasesClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,12 @@ public interface IDatabasesClient
77
Task<Database> RetrieveAsync(string databaseId);
88
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);
99
Task<PaginatedList<Database>> ListAsync(DatabasesListParameters databasesListParameters = null);
10+
11+
/// <summary>
12+
/// Creates a database as a subpage in the specified parent page, with the specified properties schema.
13+
/// </summary>
14+
/// <param name="databasesCreateParameters"></param>
15+
/// <returns>Database</returns>
16+
Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters);
1017
}
1118
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace Notion.Client
4+
{
5+
public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters
6+
{
7+
public ParentPageInput Parent { get; set; }
8+
public Dictionary<string, IPropertySchema> Properties { get; set; }
9+
public List<RichTextBaseInput> Title { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace Notion.Client
4+
{
5+
public interface IDatabasesCreateBodyParameters
6+
{
7+
ParentPageInput Parent { get; set; }
8+
Dictionary<string, IPropertySchema> Properties { get; set; }
9+
List<RichTextBaseInput> Title { get; set; }
10+
}
11+
}
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 interface IDatabasesCreateQueryParameters
4+
{
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Notion.Client
2+
{
3+
public class MentionInput
4+
{
5+
public string Type { get; set; }
6+
public Person User { get; set; }
7+
public ObjectId Page { get; set; }
8+
public ObjectId Database { get; set; }
9+
public DatePropertyValue Date { get; set; }
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class ParentPageInput
6+
{
7+
[JsonProperty("page_id")]
8+
public string PageId { get; set; }
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace Notion.Client
4+
{
5+
public class CheckboxPropertySchema : IPropertySchema
6+
{
7+
public Dictionary<string, object> Checkbox { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)