Skip to content

Commit 4442bd2

Browse files
Add support for Update Database API ✨
1 parent bf2ea89 commit 4442bd2

20 files changed

+189
-0
lines changed

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+
}
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 FilesUpdatePropertySchema : IUpdatePropertySchema
6+
{
7+
public Dictionary<string, object> File { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)