diff --git a/src/PackageRegistryService/Pages/Components/PackageAvailableVersion.cs b/src/PackageRegistryService/Pages/Components/PackageAvailableVersion.cs new file mode 100644 index 0000000..9f1da44 --- /dev/null +++ b/src/PackageRegistryService/Pages/Components/PackageAvailableVersion.cs @@ -0,0 +1,36 @@ +using PackageRegistryService.Models; + +namespace PackageRegistryService.Pages.Components +{ + public class PackageAvailableVersion + { + public static string Render(string packageName, string version) => $@"{version}"; + + public static string RenderVersionTable(ValidationPackage[] packages) + { + + var content = $@" + + + + + + + + {string.Join( + System.Environment.NewLine, + packages + .OrderByDescending(p => p.MajorVersion) + .ThenByDescending(p => p.MinorVersion) + .ThenByDescending(p => p.PatchVersion) + .Select(p => $@" + + + "))} + +"; + return content; + + } + } +} diff --git a/src/PackageRegistryService/Pages/Components/PackageDescription.cs b/src/PackageRegistryService/Pages/Components/PackageDescription.cs new file mode 100644 index 0000000..fefb71e --- /dev/null +++ b/src/PackageRegistryService/Pages/Components/PackageDescription.cs @@ -0,0 +1,26 @@ +namespace PackageRegistryService.Pages.Components +{ + public class PackageDescription + { + public static string Render(string description) + { + return String.Join( + System.Environment.NewLine, + description + .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None) + .Select(l => $@"

{l}

") + ); + + } + public static string RenderSmall(string description) + { + return String.Join( + System.Environment.NewLine, + description + .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None) + .Select(l => $@"{l}") + ); + + } + } +} diff --git a/src/PackageRegistryService/Pages/Components/PackageReleaseNotes.cs b/src/PackageRegistryService/Pages/Components/PackageReleaseNotes.cs new file mode 100644 index 0000000..bac32f7 --- /dev/null +++ b/src/PackageRegistryService/Pages/Components/PackageReleaseNotes.cs @@ -0,0 +1,39 @@ +namespace PackageRegistryService.Pages.Components +{ + public class PackageReleaseNotes + { + public static string Render(string? releaseNotes) + { + if (releaseNotes == null) + { + return "

No release notes available for this version

"; + } + else + { + return String.Join( + System.Environment.NewLine, + releaseNotes + .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None) + .Select(l => $@"

{l}

") + ); + } + } + public static string RenderSmall(string? releaseNotes) + { + if (releaseNotes == null) + { + return "

No release notes available for this version

"; + } + else + { + return String.Join( + System.Environment.NewLine, + releaseNotes + .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None) + .Select(l => $@"{l}") + ); + + } + } + } +} diff --git a/src/PackageRegistryService/Pages/Components/PackageSummary.cs b/src/PackageRegistryService/Pages/Components/PackageSummary.cs index e99a8dc..fda80c9 100644 --- a/src/PackageRegistryService/Pages/Components/PackageSummary.cs +++ b/src/PackageRegistryService/Pages/Components/PackageSummary.cs @@ -4,23 +4,14 @@ namespace PackageRegistryService.Pages.Components { public record PackageSummary(string Name, string Description, string [] Tags, string LatestVersion, DateOnly ReleaseDate) { - public static string RenderDescription(string description) - { - return String.Join( - System.Environment.NewLine, - description - .Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None) - .Select(l => $@"{l}") - ); - } public static string Render(PackageSummary summary) { return $@" - + - +"; } diff --git a/src/PackageRegistryService/Pages/Components/PackageTag.cs b/src/PackageRegistryService/Pages/Components/PackageTag.cs new file mode 100644 index 0000000..03ce5d8 --- /dev/null +++ b/src/PackageRegistryService/Pages/Components/PackageTag.cs @@ -0,0 +1,19 @@ +namespace PackageRegistryService.Pages.Components +{ + public class PackageTag + { + public static string Render(string tagName) => $@"{tagName}"; + + public static string RenderAllInline(string[]? tags) + { + if (tags == null) + { + return ""; + } + else + { + return String.Join("; ", tags.Select(t => Render(t))); + } + } + } +} diff --git a/src/PackageRegistryService/Pages/Package.cs b/src/PackageRegistryService/Pages/Package.cs index 59f34bb..c517eae 100644 --- a/src/PackageRegistryService/Pages/Package.cs +++ b/src/PackageRegistryService/Pages/Package.cs @@ -2,12 +2,18 @@ using Microsoft.EntityFrameworkCore; using PackageRegistryService.Models; using PackageRegistryService.Pages.Components; +using System.Text; namespace PackageRegistryService.Pages { public static class Package { - public static async Task Render(string packageName, ValidationPackageDb database) + public static async Task> Render(string packageName, string version, ValidationPackageDb database) + { + var content = $"{packageName}, {version}"; + return TypedResults.Text(content: content, contentType: "text/html"); + } + public static async Task> RenderLatest(string packageName, ValidationPackageDb database) { var packages = await database.ValidationPackages @@ -21,21 +27,55 @@ public static async Task Render(string packageName, Validatio .ThenByDescending(p => p.PatchVersion) .FirstOrDefault(); - var content = Layout.Render( + if (latestPackage == null) + { + return TypedResults.NotFound(); + } + + var content = $@"
+
+

Validation Package {packageName}

+

{PackageTag.RenderAllInline(latestPackage.Tags)}

+

v{latestPackage.GetSemanticVersionString()}

+
+
+
+
+

Install with arc-validate

+
 arc-validate package install {packageName} --package-version {latestPackage.GetSemanticVersionString()}
+
+
+
+

Description

+ {PackageDescription.Render(latestPackage.Description)} +
+
+
+
+ Release notes + {PackageReleaseNotes.Render(latestPackage.ReleaseNotes)} +
+
+
+ Browse code (v{latestPackage.GetSemanticVersionString()}) +
{Encoding.UTF8.GetString(latestPackage.PackageContent)}
+
+
+
+ Available versions + {PackageAvailableVersion.RenderVersionTable(packages)} +
+
+
+"; + + var page = Layout.Render( activeNavbarItem: "", title: $"Package {packageName} - ARC validation package registry API", - content: $@"

Validation Package {packageName}

-
-
-arc-validate package install {packageName}
-
-arc-validate package install {packageName} --package-version {latestPackage.GetSemanticVersionString()}
-
-
-" + content: content ); - return TypedResults.Text(content: content, contentType: "text/html"); + return TypedResults.Text(content: page, contentType: "text/html"); } } } diff --git a/src/PackageRegistryService/Pages/PageEndpoints.cs b/src/PackageRegistryService/Pages/PageEndpoints.cs index 2af553f..8a8624c 100644 --- a/src/PackageRegistryService/Pages/PageEndpoints.cs +++ b/src/PackageRegistryService/Pages/PageEndpoints.cs @@ -8,7 +8,9 @@ public static RouteGroupBuilder MapPageEndpoints(this RouteGroupBuilder group) group.MapGet("packages", Packages.Render); - group.MapGet("package/{packageName}", Package.Render); + group.MapGet("package/{packageName}", Package.RenderLatest); + + group.MapGet("package/{packageName}/{version}", Package.Render); return group; }
VersionReleased on
{Render(p.Name, p.GetSemanticVersionString())}{p.ReleaseDate}
{summary.Name}{RenderDescription(summary.Description)}{PackageDescription.RenderSmall(summary.Description)} {summary.LatestVersion} {summary.ReleaseDate}{string.Join("; ", summary.Tags.Select(t => $@"{t}"))}{string.Join("; ", summary.Tags.Select(PackageTag.Render))}