8000 Merge pull request #150 from notion-dotnet/feature/146-add-icon-and-c… · notion-dotnet/notion-sdk-net@fb7c8ef · GitHub
[go: up one dir, main page]

Skip to content

Commit fb7c8ef

Browse filesBrowse files
Merge pull request #150 from notion-dotnet/feature/146-add-icon-and-cover-images-support-for-page-and-database
Add icon and cover images support for page and database 💖
2 parents 5e887ed + 3eafdf5 commit fb7c8ef

File tree

10 files changed

+119
-13
lines changed

10 files changed

+119
-13
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
56
public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters
67
{
8+
[JsonProperty("parent")]
79
public ParentPageInput Parent { get; set; }
10+
11+
[JsonProperty("properties")]
812
public Dictionary<string, IPropertySchema> Properties { get; set; }
13+
14+
[JsonProperty("title")]
915
public List<RichTextBaseInput> Title { get; set; }
16+
17+
[JsonProperty("icon")]
18+
public IPageIcon Icon { get; set; }
19+
20+
[JsonProperty("cover")]
21+
public FileObject Cover { get; set; }
1022
}
1123
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
56
public interface IDatabasesUpdateBodyParameters
67
{
8+
[JsonProperty("properties")]
79
Dictionary<string, IUpdatePropertySchema> Properties { get; set; }
10+
11+
[JsonProperty("title")]
812
List<RichTextBaseInput> Title { get; set; }
13+
14+
[JsonProperty("icon")]
15+
IPageIcon Icon { get; set; }
16+
17+
[JsonProperty("cover")]
18+
FileObject Cover { get; set; }
919
}
1020

1121
public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters
1222
{
1323
public Dictionary<string, IUpdatePropertySchema> Properties { get; set; }
1424
public List<RichTextBaseInput> Title { get; set; }
25+
public IPageIcon Icon { get; set; }
26+
public FileObject Cover { get; set; }
1527
}
1628
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
5 8000 6
public class PagesUpdateParameters : IPagesUpdateBodyParameters
67
{
78
public bool Archived { get; set; }
9+
810
public IDictionary<string, PropertyValue> Properties { get; set; }
11+
12+
[JsonProperty("icon")]
13+
public IPageIcon Icon { get; set; }
14+
15+
[JsonProperty("cover")]
16+
public FileObject Cover { get; set; }
917
}
1018
}

Src/Notion.Client/Models/Database/Database.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ public class Database : IObject
1616
[JsonProperty("last_edited_time")]
1717
public DateTime LastEditedTime { get; set; }
1818

19+
[JsonProperty("title")]
1920
public List<RichTextBase> Title { get; set; }
2021

22+
[JsonProperty("properties")]
2123
public Dictionary<string, Property> Properties { get; set; }
2224

25+
[JsonProperty("parent")]
2326
public IDatabaseParent Parent { get; set; }
27+
28+
[JsonProperty("icon")]
29+
public IPageIcon Icon { get; set; }
30+
31+
[JsonProperty("cover")]
32+
public FileObject Cover { get; set; }
2433
}
2534
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class EmojiObject : IPageIcon
6+
{
7+
[JsonProperty("type")]
8+
public string Type { get; set; }
9+
10+
[JsonProperty("emoji")]
11+
public string Emoji { get; set; }
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using JsonSubTypes;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
6+
namespace Notion.Client
7+
{
8+
[JsonConverter(typeof(JsonSubtypes), "type")]
9+
[JsonSubtypes.KnownSubType(typeof(UploadedFile), "file")]
10+
[JsonSubtypes.KnownSubType(typeof(ExternalFile), "external")]
11+
public abstract class FileObject : IPageIcon
12+
{
13+
[JsonProperty("type")]
14+
[JsonConverter(typeof(StringEnumConverter))]
15+
public virtual string Type { get; set; }
16+
17+
[JsonProperty("url")]
18+
public string Url { get; set; }
19+
}
20+
21+
public class UploadedFile : FileObject
22+
{
23+
public override string Type => "file";
24+
25+
[JsonProperty("expiry_time")]
26+
public DateTime ExpiryTime { get; set; }
27+
}
28+
29+
public class ExternalFile : FileObject
30+
{
31+
public override string Type => "external";
32+
}
33+
}
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 interface IPageIcon
6+
{
7+
[JsonProperty("type")]
8+
string Type { get; set; }
9+
}
10+
}

Src/Notion.Client/Models/Page/NewPage.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
56
public class NewPage
67
{
7-
/// <summary>
8-
/// Constructor without arguments: added for class initializations using class literals.
9-
/// </summary>
10-
public NewPage()
11-
{
12-
Properties = new Dictionary<string, PropertyValue>();
13-
Children = new List<Block>();
14-
}
15-
168
/// <summary>
179
/// Constructor that adds required <c>Parent</c> property. Used when you don't want to
1810
/// assign properties in separate operations.
@@ -24,12 +16,21 @@ public NewPage(IPageParent parent)
2416
Children = new List<Block>();
2517
}
2618

19+
[JsonProperty("parent")]
2720
public IPageParent Parent { get; set; }
2821

22+
[JsonProperty("properties")]
2923
public Dictionary<string, PropertyValue> Properties { get; set; }
3024

25+
[JsonProperty("children")]
3126
public List<Block> Children { get; set; }
3227

28+
[JsonProperty("icon")]
29+
public IPageIcon Icon { get; set; }
30+
31+
[JsonProperty("cover")]
32+
public FileObject Cover { get; set; }
33+
3334
public NewPage AddProperty(string nameOrId, PropertyValue value)
3435
{
3536
Properties[nameOrId] = value;

Src/Notion.Client/Models/Page/Page.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Page : IObject
1010

1111
public string Id { get; set; }
1212

13+
[JsonProperty("parent")]
1314
public IPageParent Parent { get; set; }
1415

1516
[JsonProperty("created_time")]
@@ -21,8 +22,16 @@ public class Page : IObject
2122
[JsonProperty("archived")]
2223
public bool IsArchived { get; set; }
2324

25+
[JsonProperty("properties")]
2426
public IDictionary<string, PropertyValue> Properties { get; set; }
2527

28+
[JsonProperty("url")]
2629
public string Url { get; set; }
30+
31+
[JsonProperty("icon")]
32+
public IPageIcon Icon { get; set; }
33+
34+
[JsonProperty("cover")]
35+
public FileObject Cover { get; set; }
2736
}
2837
}

Test/Notion.UnitTests/PagesClientTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ public async Task CreateAsync()
5656
.WithBody(jsonData)
5757
);
5858

59-
var newPage = new NewPage();
60-
newPage.Parent = new PageParent
59+
var newPage = new NewPage(new PageParent
6160
{
6261
PageId = "3c357473-a281-49a4-88c0-10d2b245a589"
63-
};
62+
});
6463

6564
newPage.AddProperty("Name", new TitlePropertyValue()
6665
{
@@ -210,7 +209,7 @@ public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Nul
210209
[Fact]
211210
public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing()
212211
{
213-
var newPage = new NewPage();
212+
var newPage = new NewPage(null);
214213

215214
Func<Task> act = async () => await _client.CreateAsync(newPage);
216215

0 commit comments

Comments
 (0)
0