Skip to content

Commit

Permalink
Merge pull request #6 from WindowsAppCommunity/Arlodotexe/refactor-mo…
Browse files Browse the repository at this point in the history
…dels

Refactor models according to refined API spec
  • Loading branch information
Arlodotexe authored Nov 30, 2024
2 parents 81806e0 + fbf3eca commit b5e3d65
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 221 deletions.
2 changes: 1 addition & 1 deletion src/IModifiableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IModifiableEntity : IReadOnlyEntity, IModifiableConnectionsColl
public Task UpdateDescriptionAsync(string description, CancellationToken cancellationToken);

/// <summary>
/// Updates the description of this entity.
/// Updates the extended description of this entity.
/// </summary>
public Task UpdateExtendedDescriptionAsync(string extendedDescription, CancellationToken cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion src/IReadOnlyEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface IReadOnlyEntity : IReadOnlyConnectionsCollection, IReadOnlyLink
event EventHandler<string>? DescriptionUpdated;

/// <summary>
/// Raised when <see cref="Description"/> is updated.
/// Raised when <see cref="ExtendedDescription"/> is updated.
/// </summary>
event EventHandler<string>? ExtendedDescriptionUpdated;

Expand Down
62 changes: 0 additions & 62 deletions src/Models/Collaborator.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ internal static partial class UpdateEventSerializationHelpers
nameof(ProjectFeatureRemoveEvent) when jObject["Feature"] is { } featureRemoveToken && featureRemoveToken.Value<string>() is { } value =>
new ProjectFeatureRemoveEvent(id, value),

nameof(ProjectCollaboratorAddEvent) when jObject["Collaborator"] is { } collaboratorAddToken && collaboratorAddToken.ToObject<Collaborator>(serializer) is { } value =>
new ProjectCollaboratorAddEvent(id, value),

nameof(ProjectCollaboratorRemoveEvent) when jObject["Collaborator"] is { } collaboratorRemoveToken && collaboratorRemoveToken.ToObject<Collaborator>(serializer) is { } value =>
new ProjectCollaboratorRemoveEvent(id, value),

nameof(ProjectLinkAddEvent) when jObject["Link"] is { } linkAddToken && linkAddToken.ToObject<Link>(serializer) is { } value =>
new ProjectLinkAddEvent(id, value),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
19 changes: 3 additions & 16 deletions src/Models/Link.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
using Newtonsoft.Json;

namespace WinAppCommunity.Sdk.Models;

/// <summary>
/// Represents the data for a link.
/// </summary>
public record Link
{
/// <summary>
/// Creates a new instance of <see cref="Link"/>.
/// </summary>
[JsonConstructor]
public Link(string url, string name, string description)
{
Url = url;
Name = name;
Description = description;
}

/// <summary>
/// The external url this link points to.
/// </summary>
public string Url { get; set; }
public required string Url { get; set; }

/// <summary>
/// A display name for this url.
/// </summary>
public string Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// A description of this url (for accessibility or display).
/// </summary>
public string Description { get; set; }
public required string Description { get; set; }
}
68 changes: 13 additions & 55 deletions src/Models/Project.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Ipfs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace WinAppCommunity.Sdk.Models;
Expand All @@ -10,70 +8,35 @@ namespace WinAppCommunity.Sdk.Models;
/// </summary>
public record Project : IName
{
/// <summary>
/// Creates a new instance of <see cref="Project"/>.
/// </summary>
[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;
}

/// <summary>
/// Creates a new instance of <see cref="Project"/>.
/// </summary>
public Project()
: this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, [], [], null, string.Empty,
DateTime.MinValue, [], null, false)
{
}

/// <summary>
/// The publisher for this project.
/// </summary>
public Cid Publisher { get; set; }
public required DagCid Publisher { get; set; }

/// <summary>
/// The name of this project.
/// </summary>
public string Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// A description of this project.
/// </summary>
public string Description { get; set; }
public required string Description { get; set; }

/// <summary>
/// A <see cref="Cid"/> pointing to a small icon for this project.
/// An extended description of this project.
/// </summary>
public Cid? Icon { get; set; }
public required string ExtendedDescription { get; set; }

/// <summary>
/// A <see cref="Cid"/> pointing to a banner or hero image for this project.
/// A list of <see cref="DagCid"/>s that point to images demonstrating this project.
/// </summary>
public Cid? HeroImage { get; set; }

/// <summary>
/// A list of <see cref="Cid"/>s that point to images demonstrating this project.
/// </summary>
public Cid[] Images { get; set; }
public DagCid[] Images { get; set; } = [];

/// <summary>
/// A list of features provided by this project.
/// </summary>
public string[] Features { get; set; }
public string[] Features { get; set; } = [];

/// <summary>
/// A hex-encoded accent color for this publisher.
Expand All @@ -83,22 +46,17 @@ public Project()
/// <summary>
/// The category defining this project, as found in an app store.
/// </summary>
public string Category { get; set; }

/// <summary>
/// The time this project was created.
/// </summary>
public DateTime CreatedAt { get; set; }
public required string Category { get; set; }

/// <summary>
/// Other projects which this project may depend on.
/// </summary>
public Cid[] Dependencies { get; set; } = [];
public DagCid[] Dependencies { get; set; } = [];

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

/// <summary>
/// Represents links to external profiles or resources added by the user.
Expand All @@ -108,7 +66,7 @@ public Project()
/// <summary>
/// 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.
/// </summary>
public Dictionary<string, DagCid> Connections { get; set; } = [];
public Dictionary<string, DagCid> Connections { get; set; } = new();

/// <summary>
/// A flag that indicates whether the profile has requested to be forgotten.
Expand All @@ -119,4 +77,4 @@ public Project()
/// A flag indicating whether this is a non-public project.
/// </summary>
public bool IsUnlisted { get; set; }
}
}
57 changes: 18 additions & 39 deletions src/Models/Publisher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Ipfs;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace WinAppCommunity.Sdk.Models;

Expand All @@ -8,46 +8,20 @@ namespace WinAppCommunity.Sdk.Models;
/// </summary>
public record Publisher : IName
{
/// <summary>
/// Creates a new instance of <see cref="Publisher"/>.
/// </summary>
[JsonConstructor]
public Publisher(string name, string description, Cid owner, Cid? icon, string? accentColor)
{
Name = name;
Description = description;
Icon = icon;
Owner = owner;
AccentColor = accentColor;
}

/// <summary>
/// Creates a new instance of <see cref="Publisher"/>.
/// </summary>
public Publisher()
: this(string.Empty, string.Empty, string.Empty, default, default)
{
}

/// <summary>
/// The Cid of the <see cref="User"/> who owns this publisher.
/// </summary>
public Cid Owner { get; set; }

/// <summary>
/// The name of the publisher.
/// </summary>
public string Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// A description of the publisher.
/// </summary>
public string Description { get; set; }
public required string Description { get; set; }

/// <summary>
/// An icon to represent this publisher.
/// An extended description of the publisher.
/// </summary>
public Cid? Icon { get; set; }
public required string ExtendedDescription { get; set; }

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

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

/// <summary>
/// Users who are registered to participate in this publisher.
/// A list of other publishers who are managed under this publisher.
/// </summary>
public Cid[] Users { get; set; } = [];
public DagCid[] ParentPublishers { get; set; } = [];

/// <summary>
/// A list of other publishers who are managed under this publisher.
/// </summary>
public Cid[] ParentPublishers { get; set; } = [];
public DagCid[] ChildPublishers { get; set; } = [];

/// <summary>
/// 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.
/// </summary>
public Dictionary<string, DagCid> Connections { get; set; } = new();

/// <summary>
/// A flag that indicates whether the profile has requested to be forgotten.
/// </summary>
public Cid[] ChildPublishers { get; set; } = [];
public bool? ForgetMe { get; set; }

/// <summary>
/// A flag indicating whether this is a non-public project.
/// </summary>
public bool IsUnlisted { get; set; }
}
}
Loading

0 comments on commit b5e3d65

Please sign in to comment.