From 6ed24aac0b4baa8b06f6f9e23f5e0db4f2639307 Mon Sep 17 00:00:00 2001 From: Arlo Date: Sat, 30 Nov 2024 16:42:13 -0600 Subject: [PATCH 1/2] Refactor models according to refined API spec Fixes #3 Refactor models to align with the refined API spec. * **Project Model Changes:** - Remove `HeroImage`, `CreatedAt`, and `Icon` properties. - Add `ExtendedDescription` property. - Remove constructor. - Provide default values for `Images`, `Features`, `Dependencies`, `Collaborators`, `Links`, and `Connections`. - Mark `Publisher`, `Name`, `Description`, `Category`, and `CreatedAt` as `required`. - Replace `Cid` with `DagCid`. - Change `Collaborators` to a `Dictionary` type. - Use an empty collection expression `[]` instead of `Array.Empty`. - Remove all JSON-related attributes. * **Publisher Model Changes:** - Remove `Owner`, `ContactEmail`, and `Icon` properties. - Add `Users + Roles`, `Connections`, `Links`, `ExtendedDescription`, and `ForgetMe` properties. - Remove constructor. - Provide default values for `Links`, `Projects`, `Users`, `ParentPublishers`, and `ChildPublishers`. - Mark `Name`, `Description`, and `Owner` as `required`. - Replace `Cid` with `DagCid`. - Use an empty collection expression `[]` instead of `Array.Empty`. - Remove all JSON-related attributes. * **User Model Changes:** - Remove `MarkdownAboutMe` and `Icon` properties. - Add `Projects + Roles`, `Publisher + Roles`, and `ExtendedDescription` properties. - Rename `MarkdownAboutMe` to `ExtendedDescription`. - Provide default values for `Connections`, `Links`, `Projects`, and `Publishers`. - Mark `Name` and `ExtendedDescription` as `required`. - Replace `Cid` with `DagCid`. - Use an empty collection expression `[]` instead of `Array.Empty`. - Remove all JSON-related attributes. * **Update Events Changes:** - Update any mention of `IsPrivate` to `IsUnlisted` in `ProjectUpdateEvent` and `PublisherUpdateEvent`. - Remove lines 31 and 33 in `ProjectUpdateEvent`. * **Link Model Changes:** - Replace `Cid` with `DagCid`. - Remove all JSON-related attributes. * **Role Model Changes:** - Mark `Name` and `Description` as `required`. * **IModifiableEntity Changes:** - Add `UpdateExtendedDescriptionAsync` method. - Add `ExtendedDescriptionUpdated` event. * **IReadOnlyEntity Changes:** - Add `ExtendedDescription` property. - Add `ExtendedDescriptionUpdated` event. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/WindowsAppCommunity/WinAppCommunity.Sdk/issues/3?shareId=XXXX-XXXX-XXXX-XXXX). --- src/IModifiableEntity.cs | 2 +- src/IReadOnlyEntity.cs | 2 +- src/Models/Collaborator.cs | 62 ----------------- src/Models/Link.cs | 19 +----- src/Models/Project.cs | 68 ++++--------------- src/Models/Publisher.cs | 57 +++++----------- src/Models/Role.cs | 14 +--- src/Models/UpdateEvents/ProjectUpdateEvent.cs | 2 +- .../UpdateEvents/PublisherUpdateEvent.cs | 2 +- src/Models/User.cs | 24 +++---- 10 files changed, 48 insertions(+), 204 deletions(-) delete mode 100644 src/Models/Collaborator.cs diff --git a/src/IModifiableEntity.cs b/src/IModifiableEntity.cs index 6f0f0a7..79dcd60 100644 --- a/src/IModifiableEntity.cs +++ b/src/IModifiableEntity.cs @@ -16,7 +16,7 @@ public interface IModifiableEntity : IReadOnlyEntity, IModifiableConnectionsColl public Task UpdateDescriptionAsync(string description, CancellationToken cancellationToken); /// - /// Updates the description of this entity. + /// Updates the extended description of this entity. /// public Task UpdateExtendedDescriptionAsync(string extendedDescription, CancellationToken cancellationToken); diff --git a/src/IReadOnlyEntity.cs b/src/IReadOnlyEntity.cs index aac6881..db7ab81 100644 --- a/src/IReadOnlyEntity.cs +++ b/src/IReadOnlyEntity.cs @@ -41,7 +41,7 @@ public interface IReadOnlyEntity : IReadOnlyConnectionsCollection, IReadOnlyLink event EventHandler? DescriptionUpdated; /// - /// Raised when is updated. + /// Raised when is updated. /// event EventHandler? ExtendedDescriptionUpdated; diff --git a/src/Models/Collaborator.cs b/src/Models/Collaborator.cs deleted file mode 100644 index a01d125..0000000 --- a/src/Models/Collaborator.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Ipfs; -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace WinAppCommunity.Sdk.Models; - -/// -/// Represents a collaborator on a . -/// -public record Collaborator : IEqualityComparer -{ - /// - /// Creates a new instance of . - /// - [JsonConstructor] - public Collaborator(Cid user, Role role) - { - User = user; - Role = role; - } - - /// - /// A pointing to the that this refers to. - /// - public Cid User { get; set; } - - /// - /// The role for the . - /// - public Role Role { get; set; } - - /// - public virtual bool Equals(Collaborator? other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return User.Equals(other.User) && Role.Equals(other.Role); - } - - /// - public bool Equals(Collaborator? x, Collaborator? y) - { - if (ReferenceEquals(x, y)) return true; - if (ReferenceEquals(x, null)) return false; - if (ReferenceEquals(y, null)) return false; - if (x.GetType() != y.GetType()) return false; - - return x.User.Equals(y.User) && x.Role.Equals(y.Role); - } - - /// - public override int GetHashCode() => GetHashCode(this); - - /// - public int GetHashCode(Collaborator obj) - { - unchecked - { - return (obj.User.GetHashCode() * 397) ^ obj.Role.GetHashCode(); - } - } -} diff --git a/src/Models/Link.cs b/src/Models/Link.cs index ea255fe..8782bde 100644 --- a/src/Models/Link.cs +++ b/src/Models/Link.cs @@ -1,5 +1,3 @@ -using Newtonsoft.Json; - namespace WinAppCommunity.Sdk.Models; /// @@ -7,29 +5,18 @@ namespace WinAppCommunity.Sdk.Models; /// public record Link { - /// - /// Creates a new instance of . - /// - [JsonConstructor] - public Link(string url, string name, string description) - { - Url = url; - Name = name; - Description = description; - } - /// /// The external url this link points to. /// - public string Url { get; set; } + public required string Url { get; set; } /// /// A display name for this url. /// - public string Name { get; set; } + public required string Name { get; set; } /// /// A description of this url (for accessibility or display). /// - public string Description { get; set; } + public required string Description { get; set; } } diff --git a/src/Models/Project.cs b/src/Models/Project.cs index 3ed4f4c..cf27efc 100644 --- a/src/Models/Project.cs +++ b/src/Models/Project.cs @@ -1,6 +1,4 @@ using Ipfs; -using Newtonsoft.Json; -using System; using System.Collections.Generic; namespace WinAppCommunity.Sdk.Models; @@ -10,70 +8,35 @@ namespace WinAppCommunity.Sdk.Models; /// public record Project : IName { - /// - /// Creates a new instance of . - /// - [JsonConstructor] - 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) - { - Publisher = publisher; - Name = name; - Description = description; - Icon = icon; - HeroImage = heroImage; - Images = images; - Features = features; - AccentColor = accentColor; - Category = category; - CreatedAt = createdAt; - Dependencies = dependencies; - ForgetMe = forgetMe; - IsUnlisted = isUnlisted; - } - - /// - /// Creates a new instance of . - /// - public Project() - : this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, [], [], null, string.Empty, - DateTime.MinValue, [], null, false) - { - } - /// /// The publisher for this project. /// - public Cid Publisher { get; set; } + public required DagCid Publisher { get; set; } /// /// The name of this project. /// - public string Name { get; set; } + public required string Name { get; set; } /// /// A description of this project. /// - public string Description { get; set; } + public required string Description { get; set; } /// - /// A pointing to a small icon for this project. + /// An extended description of this project. /// - public Cid? Icon { get; set; } + public string ExtendedDescription { get; set; } /// - /// A pointing to a banner or hero image for this project. + /// A list of s that point to images demonstrating this project. /// - public Cid? HeroImage { get; set; } - - /// - /// A list of s that point to images demonstrating this project. - /// - public Cid[] Images { get; set; } + public DagCid[] Images { get; set; } = []; /// /// A list of features provided by this project. /// - public string[] Features { get; set; } + public string[] Features { get; set; } = []; /// /// A hex-encoded accent color for this publisher. @@ -83,22 +46,17 @@ public Project() /// /// The category defining this project, as found in an app store. /// - public string Category { get; set; } - - /// - /// The time this project was created. - /// - public DateTime CreatedAt { get; set; } + public required string Category { get; set; } /// /// Other projects which this project may depend on. /// - public Cid[] Dependencies { get; set; } = []; + public DagCid[] Dependencies { get; set; } = []; /// /// The s who collaborate on this project, and their corresponding roles. /// - public Collaborator[] Collaborators { get; set; } = []; + public Dictionary Collaborators { get; set; } = new(); /// /// Represents links to external profiles or resources added by the user. @@ -108,7 +66,7 @@ public Project() /// /// 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. /// - public Dictionary Connections { get; set; } = []; + public Dictionary Connections { get; set; } = new(); /// /// A flag that indicates whether the profile has requested to be forgotten. @@ -119,4 +77,4 @@ public Project() /// A flag indicating whether this is a non-public project. /// public bool IsUnlisted { get; set; } -} \ No newline at end of file +} diff --git a/src/Models/Publisher.cs b/src/Models/Publisher.cs index dcc1ea8..fe70b86 100644 --- a/src/Models/Publisher.cs +++ b/src/Models/Publisher.cs @@ -1,5 +1,5 @@ using Ipfs; -using Newtonsoft.Json; +using System.Collections.Generic; namespace WinAppCommunity.Sdk.Models; @@ -8,46 +8,20 @@ namespace WinAppCommunity.Sdk.Models; /// public record Publisher : IName { - /// - /// Creates a new instance of . - /// - [JsonConstructor] - public Publisher(string name, string description, Cid owner, Cid? icon, string? accentColor) - { - Name = name; - Description = description; - Icon = icon; - Owner = owner; - AccentColor = accentColor; - } - - /// - /// Creates a new instance of . - /// - public Publisher() - : this(string.Empty, string.Empty, string.Empty, default, default) - { - } - - /// - /// The Cid of the who owns this publisher. - /// - public Cid Owner { get; set; } - /// /// The name of the publisher. /// - public string Name { get; set; } + public required string Name { get; set; } /// /// A description of the publisher. /// - public string Description { get; set; } + public required string Description { get; set; } /// - /// An icon to represent this publisher. + /// An extended description of the publisher. /// - public Cid? Icon { get; set; } + public string ExtendedDescription { get; set; } /// /// A hex-encoded accent color for this publisher. @@ -60,27 +34,32 @@ public Publisher() public Link[] Links { get; set; } = []; /// - /// A list of the projects registered with this publisher. + /// Users who are registered to participate in this publisher, along with their roles. /// - public Cid[] Projects { get; set; } = []; + public Dictionary Users { get; set; } = new(); /// - /// Users who are registered to participate in this publisher. + /// A list of other publishers who are managed under this publisher. /// - public Cid[] Users { get; set; } = []; + public DagCid[] ParentPublishers { get; set; } = []; /// /// A list of other publishers who are managed under this publisher. /// - public Cid[] ParentPublishers { get; set; } = []; + public DagCid[] ChildPublishers { get; set; } = []; /// - /// A list of other publishers who are managed under this publisher. + /// 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. + /// + public Dictionary Connections { get; set; } = new(); + + /// + /// A flag that indicates whether the profile has requested to be forgotten. /// - public Cid[] ChildPublishers { get; set; } = []; + public bool? ForgetMe { get; set; } /// /// A flag indicating whether this is a non-public project. /// public bool IsUnlisted { get; set; } -} \ No newline at end of file +} diff --git a/src/Models/Role.cs b/src/Models/Role.cs index 20318d0..8c14997 100644 --- a/src/Models/Role.cs +++ b/src/Models/Role.cs @@ -7,25 +7,15 @@ namespace WinAppCommunity.Sdk.Models; /// public record Role : IName { - /// - /// Creates a new instance of . - /// - [JsonConstructor] - public Role(string name, string description) - { - Name = name; - Description = description; - } - /// /// The name of the role. /// - public string Name { get; } + public required string Name { get; init; } /// /// A description for the role. /// - public string Description { get; } + public required string Description { get; init; } /// public virtual bool Equals(Role? other) diff --git a/src/Models/UpdateEvents/ProjectUpdateEvent.cs b/src/Models/UpdateEvents/ProjectUpdateEvent.cs index 2e90498..1029a80 100644 --- a/src/Models/UpdateEvents/ProjectUpdateEvent.cs +++ b/src/Models/UpdateEvents/ProjectUpdateEvent.cs @@ -38,4 +38,4 @@ public record ProjectLinkRemoveEvent(string Id, Link Link) : ProjectUpdateEvent( public record ProjectForgetMeUpdateEvent(string Id, bool? ForgetMe) : ProjectUpdateEvent(Id, nameof(ProjectForgetMeUpdateEvent)); -public record ProjectPrivacyUpdateEvent(string Id, bool IsPrivate) : ProjectUpdateEvent(Id, nameof(ProjectPrivacyUpdateEvent)); +public record ProjectPrivacyUpdateEvent(string Id, bool IsUnlisted) : ProjectUpdateEvent(Id, nameof(ProjectPrivacyUpdateEvent)); diff --git a/src/Models/UpdateEvents/PublisherUpdateEvent.cs b/src/Models/UpdateEvents/PublisherUpdateEvent.cs index fb27e7c..0da12b0 100644 --- a/src/Models/UpdateEvents/PublisherUpdateEvent.cs +++ b/src/Models/UpdateEvents/PublisherUpdateEvent.cs @@ -34,4 +34,4 @@ public record PublisherParentPublisherAddEvent(string Id, Cid ParentPublisher) : public record PublisherParentPublisherRemoveEvent(string Id, Cid ParentPublisher) : PublisherUpdateEvent(Id, nameof(PublisherParentPublisherRemoveEvent)); -public record PublisherPrivateFlagUpdateEvent(string Id, bool IsPrivate) : PublisherUpdateEvent(Id, nameof(PublisherPrivateFlagUpdateEvent)); +public record PublisherPrivateFlagUpdateEvent(string Id, bool IsUnlisted) : PublisherUpdateEvent(Id, nameof(PublisherPrivateFlagUpdateEvent)); diff --git a/src/Models/User.cs b/src/Models/User.cs index 9aed428..0ecc97c 100644 --- a/src/Models/User.cs +++ b/src/Models/User.cs @@ -1,14 +1,11 @@ using Ipfs; -using System; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace WinAppCommunity.Sdk.Models; /// /// Represents a user. /// -[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] public record User : IName { /// @@ -17,19 +14,14 @@ public record User : IName public required string Name { get; set; } /// - /// A summary of the user in markdown syntax. + /// An extended description of the user in markdown syntax. /// - public required string MarkdownAboutMe { get; set; } - - /// - /// An icon to represent this user. - /// - public Cid? Icon { get; set; } + public required string ExtendedDescription { get; set; } /// /// Represents application connections added by the user. /// - public Dictionary Connections { get; set; } = []; + public Dictionary Connections { get; set; } = new(); /// /// Represents links to external profiles or resources added by the user. @@ -37,17 +29,17 @@ public record User : IName public Link[] Links { get; set; } = []; /// - /// A list of all the projects the user is registered on. + /// A list of all the projects the user is registered on, along with their roles. /// - public Cid[] Projects { get; set; } = []; + public Dictionary Projects { get; set; } = new(); /// - /// Represents all publishers the user is registered on. + /// Represents all publishers the user is registered on, along with their roles. /// - public Cid[] Publishers { get; set; } = []; + public Dictionary Publishers { get; set; } = new(); /// /// A flag that indicates whether the profile has requested to be forgotten. /// public bool? ForgetMe { get; set; } -} \ No newline at end of file +} From fbf3ecab941725852335edeef23f153a97933236 Mon Sep 17 00:00:00 2001 From: Arlo Date: Sat, 30 Nov 2024 16:51:15 -0600 Subject: [PATCH 2/2] Cleanup collaborator serialization helpers and properties --- .../UpdateEventSerializationHelpers.Read.cs | 6 ------ .../UpdateEventSerializationHelpers.Write.cs | 8 +------- src/Models/Project.cs | 2 +- src/Models/Publisher.cs | 2 +- src/Models/UpdateEvents/ProjectUpdateEvent.cs | 4 ---- 5 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Models/JsonConverters/UpdateEventSerializationHelpers.Read.cs b/src/Models/JsonConverters/UpdateEventSerializationHelpers.Read.cs index 7a71bf9..c0c4825 100644 --- a/src/Models/JsonConverters/UpdateEventSerializationHelpers.Read.cs +++ b/src/Models/JsonConverters/UpdateEventSerializationHelpers.Read.cs @@ -122,12 +122,6 @@ internal static partial class UpdateEventSerializationHelpers nameof(ProjectFeatureRemoveEvent) when jObject["Feature"] is { } featureRemoveToken && featureRemoveToken.Value() is { } value => new ProjectFeatureRemoveEvent(id, value), - nameof(ProjectCollaboratorAddEvent) when jObject["Collaborator"] is { } collaboratorAddToken && collaboratorAddToken.ToObject(serializer) is { } value => - new ProjectCollaboratorAddEvent(id, value), - - nameof(ProjectCollaboratorRemoveEvent) when jObject["Collaborator"] is { } collaboratorRemoveToken && collaboratorRemoveToken.ToObject(serializer) is { } value => - new ProjectCollaboratorRemoveEvent(id, value), - nameof(ProjectLinkAddEvent) when jObject["Link"] is { } linkAddToken && linkAddToken.ToObject(serializer) is { } value => new ProjectLinkAddEvent(id, value), diff --git a/src/Models/JsonConverters/UpdateEventSerializationHelpers.Write.cs b/src/Models/JsonConverters/UpdateEventSerializationHelpers.Write.cs index d1a9a6f..60a6284 100644 --- a/src/Models/JsonConverters/UpdateEventSerializationHelpers.Write.cs +++ b/src/Models/JsonConverters/UpdateEventSerializationHelpers.Write.cs @@ -114,12 +114,6 @@ private static void WriteProject(WinAppCommunityUpdateEvent @event, JObject jObj case ProjectDependencyRemoveEvent projectDependencyRemoveEvent: jObject.Add("Dependency", JValue.CreateString(projectDependencyRemoveEvent.Dependency.ToString())); break; - case ProjectCollaboratorAddEvent projectCollaboratorAddEvent: - jObject.Add("Collaborator", JObject.FromObject(projectCollaboratorAddEvent.Collaborator)); - break; - case ProjectCollaboratorRemoveEvent projectCollaboratorRemoveEvent: - jObject.Add("Collaborator", JObject.FromObject(projectCollaboratorRemoveEvent.Collaborator)); - break; case ProjectLinkAddEvent projectLinkAddEvent: jObject.Add("Link", JObject.FromObject(projectLinkAddEvent.Link)); break; @@ -139,7 +133,7 @@ private static void WriteProject(WinAppCommunityUpdateEvent @event, JObject jObj : new JValue(projectForgetMeUpdateEvent.ForgetMe.Value)); break; case ProjectPrivacyUpdateEvent projectPrivacyUpdateEvent: - jObject.Add("IsPrivate", new JValue(projectPrivacyUpdateEvent.IsPrivate)); + jObject.Add("IsUnlisted", new JValue(projectPrivacyUpdateEvent.IsUnlisted)); break; } } diff --git a/src/Models/Project.cs b/src/Models/Project.cs index cf27efc..e6d6bab 100644 --- a/src/Models/Project.cs +++ b/src/Models/Project.cs @@ -26,7 +26,7 @@ public record Project : IName /// /// An extended description of this project. /// - public string ExtendedDescription { get; set; } + public required string ExtendedDescription { get; set; } /// /// A list of s that point to images demonstrating this project. diff --git a/src/Models/Publisher.cs b/src/Models/Publisher.cs index fe70b86..abfb56d 100644 --- a/src/Models/Publisher.cs +++ b/src/Models/Publisher.cs @@ -21,7 +21,7 @@ public record Publisher : IName /// /// An extended description of the publisher. /// - public string ExtendedDescription { get; set; } + public required string ExtendedDescription { get; set; } /// /// A hex-encoded accent color for this publisher. diff --git a/src/Models/UpdateEvents/ProjectUpdateEvent.cs b/src/Models/UpdateEvents/ProjectUpdateEvent.cs index 1029a80..c27add4 100644 --- a/src/Models/UpdateEvents/ProjectUpdateEvent.cs +++ b/src/Models/UpdateEvents/ProjectUpdateEvent.cs @@ -28,10 +28,6 @@ public record ProjectDependencyAddEvent(string Id, Cid Dependency) : ProjectUpda public record ProjectDependencyRemoveEvent(string Id, Cid Dependency) : ProjectUpdateEvent(Id, nameof(ProjectDependencyRemoveEvent)); -public record ProjectCollaboratorAddEvent(string Id, Collaborator Collaborator) : ProjectUpdateEvent(Id, nameof(ProjectCollaboratorAddEvent)); - -public record ProjectCollaboratorRemoveEvent(string Id, Collaborator Collaborator) : ProjectUpdateEvent(Id, nameof(ProjectCollaboratorRemoveEvent)); - public record ProjectLinkAddEvent(string Id, Link Link) : ProjectUpdateEvent(Id, nameof(ProjectLinkAddEvent)); public record ProjectLinkRemoveEvent(string Id, Link Link) : ProjectUpdateEvent(Id, nameof(ProjectLinkRemoveEvent));