From 00b012ee3132eb00665777c7f00b1da24e01b6f3 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 23 Feb 2024 17:01:16 +0100 Subject: [PATCH] Add simple package page --- .../Data/arc-validate-package-index.json | 2 +- .../Pages/Components/Layout.cs | 2 +- .../Pages/Components/PackageSummary.cs | 15 +++++++- src/PackageRegistryService/Pages/Package.cs | 37 ++++++++++++++++++- .../Pages/PageEndpoints.cs | 2 + 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/PackageRegistryService/Data/arc-validate-package-index.json b/src/PackageRegistryService/Data/arc-validate-package-index.json index f91813c..0b688b8 100644 --- a/src/PackageRegistryService/Data/arc-validate-package-index.json +++ b/src/PackageRegistryService/Data/arc-validate-package-index.json @@ -2,7 +2,7 @@ { "RepoPath": "src/PackageRegistryService/StagingArea/invenio/invenio@1.0.0.fsx", "FileName": "invenio@1.0.0.fsx", - "LastUpdated": "2024-02-23T16:27:27+01:00", + "LastUpdated": "2024-02-23T16:27:26+01:00", "Metadata": { "Name": "invenio", "Description": "Validates if the ARC contains the necessary metadata to be publishable via Invenio.\nThe following metadata is required:\n - Investigation has title and description\n - All persons in Investigation Contacts must have a name, last name, affiliation and valid email\n", diff --git a/src/PackageRegistryService/Pages/Components/Layout.cs b/src/PackageRegistryService/Pages/Components/Layout.cs index fc172da..6782716 100644 --- a/src/PackageRegistryService/Pages/Components/Layout.cs +++ b/src/PackageRegistryService/Pages/Components/Layout.cs @@ -10,7 +10,7 @@ public static string Render(string activeNavbarItem, string title, string conten - + {title} diff --git a/src/PackageRegistryService/Pages/Components/PackageSummary.cs b/src/PackageRegistryService/Pages/Components/PackageSummary.cs index 51f7932..e99a8dc 100644 --- a/src/PackageRegistryService/Pages/Components/PackageSummary.cs +++ b/src/PackageRegistryService/Pages/Components/PackageSummary.cs @@ -1,12 +1,23 @@ -namespace PackageRegistryService.Pages.Components +using YamlDotNet.Core.Tokens; + +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 $@" {summary.Name} -{summary.Description} +{RenderDescription(summary.Description)} {summary.LatestVersion} {summary.ReleaseDate} {string.Join("; ", summary.Tags.Select(t => $@"{t}"))} diff --git a/src/PackageRegistryService/Pages/Package.cs b/src/PackageRegistryService/Pages/Package.cs index 735c5aa..59f34bb 100644 --- a/src/PackageRegistryService/Pages/Package.cs +++ b/src/PackageRegistryService/Pages/Package.cs @@ -1,6 +1,41 @@ -namespace PackageRegistryService.Pages +using Microsoft.AspNetCore.Http.HttpResults; +using Microsoft.EntityFrameworkCore; +using PackageRegistryService.Models; +using PackageRegistryService.Pages.Components; + +namespace PackageRegistryService.Pages { public static class Package { + public static async Task Render(string packageName, ValidationPackageDb database) + { + var packages = await + database.ValidationPackages + .Where(p => p.Name == packageName) + .ToArrayAsync(); + + var latestPackage = + packages + .OrderByDescending(p => p.MajorVersion) + .ThenByDescending(p => p.MinorVersion) + .ThenByDescending(p => p.PatchVersion) + .FirstOrDefault(); + + var content = 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()}
+
+
+" + ); + + return TypedResults.Text(content: content, contentType: "text/html"); + } } } diff --git a/src/PackageRegistryService/Pages/PageEndpoints.cs b/src/PackageRegistryService/Pages/PageEndpoints.cs index 44f3239..2af553f 100644 --- a/src/PackageRegistryService/Pages/PageEndpoints.cs +++ b/src/PackageRegistryService/Pages/PageEndpoints.cs @@ -8,6 +8,8 @@ public static RouteGroupBuilder MapPageEndpoints(this RouteGroupBuilder group) group.MapGet("packages", Packages.Render); + group.MapGet("package/{packageName}", Package.Render); + return group; } }