Skip to content

Commit b5e3d65

Browse files
authored
Merge pull request #6 from WindowsAppCommunity/Arlodotexe/refactor-models
Refactor models according to refined API spec
2 parents 81806e0 + fbf3eca commit b5e3d65

12 files changed

Lines changed: 49 additions & 221 deletions

src/IModifiableEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IModifiableEntity : IReadOnlyEntity, IModifiableConnectionsColl
1616
public Task UpdateDescriptionAsync(string description, CancellationToken cancellationToken);
1717

1818
/// <summary>
19-
/// Updates the description of this entity.
19+
/// Updates the extended description of this entity.
2020
/// </summary>
2121
public Task UpdateExtendedDescriptionAsync(string extendedDescription, CancellationToken cancellationToken);
2222

src/IReadOnlyEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface IReadOnlyEntity : IReadOnlyConnectionsCollection, IReadOnlyLink
4141
event EventHandler<string>? DescriptionUpdated;
4242

4343
/// <summary>
44-
/// Raised when <see cref="Description"/> is updated.
44+
/// Raised when <see cref="ExtendedDescription"/> is updated.
4545
/// </summary>
4646
event EventHandler<string>? ExtendedDescriptionUpdated;
4747

src/Models/Collaborator.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/Models/JsonConverters/UpdateEventSerializationHelpers.Read.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ internal static partial class UpdateEventSerializationHelpers
122122
nameof(ProjectFeatureRemoveEvent) when jObject["Feature"] is { } featureRemoveToken && featureRemoveToken.Value<string>() is { } value =>
123123
new ProjectFeatureRemoveEvent(id, value),
124124

125-
nameof(ProjectCollaboratorAddEvent) when jObject["Collaborator"] is { } collaboratorAddToken && collaboratorAddToken.ToObject<Collaborator>(serializer) is { } value =>
126-
new ProjectCollaboratorAddEvent(id, value),
127-
128-
nameof(ProjectCollaboratorRemoveEvent) when jObject["Collaborator"] is { } collaboratorRemoveToken && collaboratorRemoveToken.ToObject<Collaborator>(serializer) is { } value =>
129-
new ProjectCollaboratorRemoveEvent(id, value),
130-
131125
nameof(ProjectLinkAddEvent) when jObject["Link"] is { } linkAddToken && linkAddToken.ToObject<Link>(serializer) is { } value =>
132126
new ProjectLinkAddEvent(id, value),
133127

src/Models/JsonConverters/UpdateEventSerializationHelpers.Write.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ private static void WriteProject(WinAppCommunityUpdateEvent @event, JObject jObj
114114
case ProjectDependencyRemoveEvent projectDependencyRemoveEvent:
115115
jObject.Add("Dependency", JValue.CreateString(projectDependencyRemoveEvent.Dependency.ToString()));
116116
break;
117-
case ProjectCollaboratorAddEvent projectCollaboratorAddEvent:
118-
jObject.Add("Collaborator", JObject.FromObject(projectCollaboratorAddEvent.Collaborator));
119-
break;
120-
case ProjectCollaboratorRemoveEvent projectCollaboratorRemoveEvent:
121-
jObject.Add("Collaborator", JObject.FromObject(projectCollaboratorRemoveEvent.Collaborator));
122-
break;
123117
case ProjectLinkAddEvent projectLinkAddEvent:
124118
jObject.Add("Link", JObject.FromObject(projectLinkAddEvent.Link));
125119
break;
@@ -139,7 +133,7 @@ private static void WriteProject(WinAppCommunityUpdateEvent @event, JObject jObj
139133
: new JValue(projectForgetMeUpdateEvent.ForgetMe.Value));
140134
break;
141135
case ProjectPrivacyUpdateEvent projectPrivacyUpdateEvent:
142-
jObject.Add("IsPrivate", new JValue(projectPrivacyUpdateEvent.IsPrivate));
136+
jObject.Add("IsUnlisted", new JValue(projectPrivacyUpdateEvent.IsUnlisted));
143137
break;
144138
}
145139
}

src/Models/Link.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
using Newtonsoft.Json;
2-
31
namespace WinAppCommunity.Sdk.Models;
42

53
/// <summary>
64
/// Represents the data for a link.
75
/// </summary>
86
public record Link
97
{
10-
/// <summary>
11-
/// Creates a new instance of <see cref="Link"/>.
12-
/// </summary>
13-
[JsonConstructor]
14-
public Link(string url, string name, string description)
15-
{
16-
Url = url;
17-
Name = name;
18-
Description = description;
19-
}
20-
218
/// <summary>
229
/// The external url this link points to.
2310
/// </summary>
24-
public string Url { get; set; }
11+
public required string Url { get; set; }
2512

2613
/// <summary>
2714
/// A display name for this url.
2815
/// </summary>
29-
public string Name { get; set; }
16+
public required string Name { get; set; }
3017

3118
/// <summary>
3219
/// A description of this url (for accessibility or display).
3320
/// </summary>
34-
public string Description { get; set; }
21+
public required string Description { get; set; }
3522
}

src/Models/Project.cs

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Ipfs;
2-
using Newtonsoft.Json;
3-
using System;
42
using System.Collections.Generic;
53

64
namespace WinAppCommunity.Sdk.Models;
@@ -10,70 +8,35 @@ namespace WinAppCommunity.Sdk.Models;
108
/// </summary>
119
public record Project : IName
1210
{
13-
/// <summary>
14-
/// Creates a new instance of <see cref="Project"/>.
15-
/// </summary>
16-
[JsonConstructor]
17-
public Project(Cid publisher, string name, string description, Cid icon, Cid heroImage, Cid[] images, string[] features, string? accentColor, string category, DateTime createdAt, Cid[] dependencies, bool? forgetMe, bool isUnlisted)
18-
{
19-
Publisher = publisher;
20-
Name = name;
21-
Description = description;
22-
Icon = icon;
23-
HeroImage = heroImage;
24-
Images = images;
25-
Features = features;
26-
AccentColor = accentColor;
27-
Category = category;
28-
CreatedAt = createdAt;
29-
Dependencies = dependencies;
30-
ForgetMe = forgetMe;
31-
IsUnlisted = isUnlisted;
32-
}
33-
34-
/// <summary>
35-
/// Creates a new instance of <see cref="Project"/>.
36-
/// </summary>
37-
public Project()
38-
: this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, [], [], null, string.Empty,
39-
DateTime.MinValue, [], null, false)
40-
{
41-
}
42-
4311
/// <summary>
4412
/// The publisher for this project.
4513
/// </summary>
46-
public Cid Publisher { get; set; }
14+
public required DagCid Publisher { get; set; }
4715

4816
/// <summary>
4917
/// The name of this project.
5018
/// </summary>
51-
public string Name { get; set; }
19+
public required string Name { get; set; }
5220

5321
/// <summary>
5422
/// A description of this project.
5523
/// </summary>
56-
public string Description { get; set; }
24+
public required string Description { get; set; }
5725

5826
/// <summary>
59-
/// A <see cref="Cid"/> pointing to a small icon for this project.
27+
/// An extended description of this project.
6028
/// </summary>
61-
public Cid? Icon { get; set; }
29+
public required string ExtendedDescription { get; set; }
6230

6331
/// <summary>
64-
/// A <see cref="Cid"/> pointing to a banner or hero image for this project.
32+
/// A list of <see cref="DagCid"/>s that point to images demonstrating this project.
6533
/// </summary>
66-
public Cid? HeroImage { get; set; }
67-
68-
/// <summary>
69-
/// A list of <see cref="Cid"/>s that point to images demonstrating this project.
70-
/// </summary>
71-
public Cid[] Images { get; set; }
34+
public DagCid[] Images { get; set; } = [];
7235

7336
/// <summary>
7437
/// A list of features provided by this project.
7538
/// </summary>
76-
public string[] Features { get; set; }
39+
public string[] Features { get; set; } = [];
7740

7841
/// <summary>
7942
/// A hex-encoded accent color for this publisher.
@@ -83,22 +46,17 @@ public Project()
8346
/// <summary>
8447
/// The category defining this project, as found in an app store.
8548
/// </summary>
86-
public string Category { get; set; }
87-
88-
/// <summary>
89-
/// The time this project was created.
90-
/// </summary>
91-
public DateTime CreatedAt { get; set; }
49+
public required string Category { get; set; }
9250

9351
/// <summary>
9452
/// Other projects which this project may depend on.
9553
/// </summary>
96-
public Cid[] Dependencies { get; set; } = [];
54+
public DagCid[] Dependencies { get; set; } = [];
9755

9856
/// <summary>
9957
/// The <see cref="User"/>s who collaborate on this project, and their corresponding roles.
10058
/// </summary>
101-
public Collaborator[] Collaborators { get; set; } = [];
59+
public Dictionary<DagCid, Role> Collaborators { get; set; } = new();
10260

10361
/// <summary>
10462
/// Represents links to external profiles or resources added by the user.
@@ -108,7 +66,7 @@ public Project()
10866
/// <summary>
10967
/// Holds information about project assets that have been published for consumption by an end user, such as a Microsoft Store app, a package on nuget.org, a git repo, etc.
11068
/// </summary>
111-
public Dictionary<string, DagCid> Connections { get; set; } = [];
69+
public Dictionary<string, DagCid> Connections { get; set; } = new();
11270

11371
/// <summary>
11472
/// A flag that indicates whether the profile has requested to be forgotten.
@@ -119,4 +77,4 @@ public Project()
11977
/// A flag indicating whether this is a non-public project.
12078
/// </summary>
12179
public bool IsUnlisted { get; set; }
122-
}
80+
}

src/Models/Publisher.cs

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Ipfs;
2-
using Newtonsoft.Json;
2+
using System.Collections.Generic;
33

44
namespace WinAppCommunity.Sdk.Models;
55

@@ -8,46 +8,20 @@ namespace WinAppCommunity.Sdk.Models;
88
/// </summary>
99
public record Publisher : IName
1010
{
11-
/// <summary>
12-
/// Creates a new instance of <see cref="Publisher"/>.
13-
/// </summary>
14-
[JsonConstructor]
15-
public Publisher(string name, string description, Cid owner, Cid? icon, string? accentColor)
16-
{
17-
Name = name;
18-
Description = description;
19-
Icon = icon;
20-
Owner = owner;
21-
AccentColor = accentColor;
22-
}
23-
24-
/// <summary>
25-
/// Creates a new instance of <see cref="Publisher"/>.
26-
/// </summary>
27-
public Publisher()
28-
: this(string.Empty, string.Empty, string.Empty, default, default)
29-
{
30-
}
31-
32-
/// <summary>
33-
/// The Cid of the <see cref="User"/> who owns this publisher.
34-
/// </summary>
35-
public Cid Owner { get; set; }
36-
3711
/// <summary>
3812
/// The name of the publisher.
3913
/// </summary>
40-
public string Name { get; set; }
14+
public required string Name { get; set; }
4115

4216
/// <summary>
4317
/// A description of the publisher.
4418
/// </summary>
45-
public string Description { get; set; }
19+
public required string Description { get; set; }
4620

4721
/// <summary>
48-
/// An icon to represent this publisher.
22+
/// An extended description of the publisher.
4923
/// </summary>
50-
public Cid? Icon { get; set; }
24+
public required string ExtendedDescription { get; set; }
5125

5226
/// <summary>
5327
/// A hex-encoded accent color for this publisher.
@@ -60,27 +34,32 @@ public Publisher()
6034
public Link[] Links { get; set; } = [];
6135

6236
/// <summary>
63-
/// A list of the projects registered with this publisher.
37+
/// Users who are registered to participate in this publisher, along with their roles.
6438
/// </summary>
65-
public Cid[] Projects { get; set; } = [];
39+
public Dictionary<DagCid, Role> Users { get; set; } = new();
6640

6741
/// <summary>
68-
/// Users who are registered to participate in this publisher.
42+
/// A list of other publishers who are managed under this publisher.
6943
/// </summary>
70-
public Cid[] Users { get; set; } = [];
44+
public DagCid[] ParentPublishers { get; set; } = [];
7145

7246
/// <summary>
7347
/// A list of other publishers who are managed under this publisher.
7448
/// </summary>
75-
public Cid[] ParentPublishers { get; set; } = [];
49+
public DagCid[] ChildPublishers { get; set; } = [];
7650

7751
/// <summary>
78-
/// A list of other publishers who are managed under this publisher.
52+
/// Holds information about publisher assets that have been published for consumption by an end user, such as a Microsoft Store app, a package on nuget.org, a git repo, etc.
53+
/// </summary>
54+
public Dictionary<string, DagCid> Connections { get; set; } = new();
55+
56+
/// <summary>
57+
/// A flag that indicates whether the profile has requested to be forgotten.
7958
/// </summary>
80-
public Cid[] ChildPublishers { get; set; } = [];
59+
public bool? ForgetMe { get; set; }
8160

8261
/// <summary>
8362
/// A flag indicating whether this is a non-public project.
8463
/// </summary>
8564
public bool IsUnlisted { get; set; }
86-
}
65+
}

0 commit comments

Comments
 (0)