Skip to content

Commit 95062af

Browse files
Merge pull request #98 from notion-dotnet/feature/80-add-support-for-update-database-api
Add support for update database API 💖
2 parents bf2ea89 + 790158c commit 95062af

26 files changed

+376
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ var complexFiler = new CompoundFilter(
9393
```
9494

9595
## Supported Endpoints
96-
- [ ] Databases
96+
- [x] Databases
9797
- [x] Retrieve a database
9898
- [x] Query a database
9999
- [x] List databases
100-
- [x] Create a Database
100+
- [x] Create a database
101+
- [x] Update database
101102
- [x] Pages
102103
- [x] Retrieve a page
103104
- [x] Create a page

Src/Notion.Client/Api/ApiEndpoints.cs

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

1314
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
@@ -44,5 +44,12 @@ public async Task<Database> CreateAsync(DatabasesCreateParameters databasesCreat
4444

4545
return await _client.PostAsync<Database>(DatabasesApiUrls.Create, body);
4646
}
47+
48+
public async Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters)
49+
{
50+
var body = (IDatabasesUpdateBodyParameters)databasesUpdateParameters;
51+
52+
return await _client.PatchAsync<Database>(DatabasesApiUrls.Update(databaseId), body);
53+
}
4754
}
4855
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ public interface IDatabasesClient
1414
/// <param name="databasesCreateParameters"></param>
1515
/// <returns>Database</returns>
1616
Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters);
17+
18+
/// <summary>
19+
/// Updates an existing database as specified by the parameters.
20+
/// </summary>
21+
/// <param name="databaseId"></param>
22+
/// <param name="databasesUpdateParameters"></param>
23+
/// <returns>Database</returns>
24+
Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters);
1725
}
1826
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace Notion.Client
4+
{
5+
public interface IDatabasesUpdateBodyParameters
6+
{
7+
Dictionary<string, IUpdatePropertySchema> Properties { get; set; }
8+
List<RichTextBaseInput> Title { get; set; }
9+
}
10+
11+
public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters
12+
{
13+
public Dictionary<string, IUpdatePropertySchema> Properties { get; set; }
14+
public List<RichTextBaseInput> Title { get; set; }
15+
}
16+
}
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 CheckboxUpdatePropertySchema : IUpdatePropertySchema
6+
{
7+
public Dictionary<string, object> Checkbox { get; set; }
8+
}
9+
}
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 CreatedByUpdatePropertySchema : IUpdatePropertySchema
7+
{
8+
[JsonProperty("created_by")]
9+
public Dictionary<string, object> CreatedBy { get; set; }
10+
}
11+
}
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 CreatedTimeUpdatePropertySchema : IUpdatePropertySchema
7+
{
8+
[JsonProperty("created_time")]
9+
public Dictionary<string, object> CreatedTime { get; set; }
10+
}
11+
}
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 DateUpdatePropertySchema : IUpdatePropertySchema
6+
{
7+
public Dictionary<string, object> Date { get; set; }
8+
}
9+
}
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 EmailUpdatePropertySchema : IUpdatePropertySchema
6+
{
7+
public Dictionary<string, object> Email { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)