diff --git a/src/PackageRegistryService/Pages/Components/Package.cs b/src/PackageRegistryService/Pages/Components/Package.cs
index c362313..2350f17 100644
--- a/src/PackageRegistryService/Pages/Components/Package.cs
+++ b/src/PackageRegistryService/Pages/Components/Package.cs
@@ -16,7 +16,8 @@ public static string Render(
DateOnly packageReleaseDate,
string[] packageTags,
Author[] packageAuthors,
- string versionTable
+ string versionTable,
+ int downloads
)
{
return $@"
@@ -25,6 +26,7 @@ string versionTable
{PackageTag.RenderAllLinksInline(packageTags)}
v{packageVersion} released on {packageReleaseDate}
by {PackageAuthor.RenderAllLinksInline(packageAuthors.Select(a => a.FullName).ToArray())}
+ {downloads} Downloads
{packageSummary}
diff --git a/src/PackageRegistryService/Pages/Components/PackageSummary.cs b/src/PackageRegistryService/Pages/Components/PackageSummary.cs
index 1313935..667b592 100644
--- a/src/PackageRegistryService/Pages/Components/PackageSummary.cs
+++ b/src/PackageRegistryService/Pages/Components/PackageSummary.cs
@@ -2,7 +2,7 @@
namespace PackageRegistryService.Pages.Components
{
- public record PackageSummary(string Name, string Summary, string [] Tags, string LatestVersion, DateOnly ReleaseDate)
+ public record PackageSummary(string Name, string Summary, string [] Tags, string LatestVersion, DateOnly ReleaseDate, int TotalDownloads)
{
public static string Render(PackageSummary summary)
{
@@ -12,6 +12,7 @@ public static string Render(PackageSummary summary)
{summary.LatestVersion} |
{summary.ReleaseDate} |
{string.Join("; ", summary.Tags.Select(PackageTag.RenderLink))} |
+{summary.TotalDownloads} |
";
}
@@ -27,6 +28,7 @@ public static string RenderList(IEnumerable summaries)
Latest version |
Release date |
Tags |
+Total Downloads |
{string.Join(System.Environment.NewLine, summaries.Select(PackageSummary.Render))}
diff --git a/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs b/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs
index 6ed07e4..6ff5523 100644
--- a/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs
+++ b/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs
@@ -29,6 +29,7 @@ public static async Task
}
var package = await database.ValidationPackages.FindAsync(packageName, major, minor, revision);
+ var downloads = await database.Downloads.FindAsync(packageName, major, minor, revision);
if (package == null)
{
@@ -53,7 +54,8 @@ public static async Task
packageDescription: package.Description,
packageReleaseNotes: package.ReleaseNotes ?? "",
packageAuthors: (package.Authors ?? []).ToArray(),
- versionTable: Components.PackageAvailableVersion.RenderVersionTable(packages)
+ versionTable: Components.PackageAvailableVersion.RenderVersionTable(packages),
+ downloads: downloads?.Downloads ?? 0
)
);
@@ -78,6 +80,8 @@ public static async Task> RenderLatest(stri
return TypedResults.NotFound();
}
+ var downloads = await database.Downloads.FindAsync(latestPackage.Name, latestPackage.MajorVersion, latestPackage.MinorVersion, latestPackage.PatchVersion);
+
var page = Layout.Render(
activeNavbarItem: "",
title: $"Package {packageName} - ARC validation package registry API",
@@ -91,7 +95,8 @@ public static async Task> RenderLatest(stri
packageDescription: latestPackage.Description,
packageReleaseNotes: latestPackage.ReleaseNotes ?? "",
packageAuthors: (latestPackage.Authors ?? []).ToArray(),
- versionTable: Components.PackageAvailableVersion.RenderVersionTable(packages)
+ versionTable: Components.PackageAvailableVersion.RenderVersionTable(packages),
+ downloads: downloads?.Downloads ?? 0
)
);
diff --git a/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs b/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs
index 4a8d880..2c0168b 100644
--- a/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs
+++ b/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs
@@ -28,19 +28,26 @@ public static async Task Render(ValidationPackageDb database)
.ToList()
.Select(group =>
{
+ var downloads =
+ database.Downloads
+ .Where(p => p.PackageName == group.Key)
+ .Sum(d => d.Downloads);
+
var latestPackage =
group
.OrderByDescending(p => p.MajorVersion)
.ThenByDescending(p => p.MinorVersion)
.ThenByDescending(p => p.PatchVersion)
.FirstOrDefault();
+
return
new PackageSummary(
Name: group.Key,
Tags: (latestPackage.Tags ?? []).Select(t => t.Name).ToArray(),
Summary: latestPackage.Summary,
ReleaseDate: latestPackage.ReleaseDate,
- LatestVersion: latestPackage.GetSemanticVersionString()
+ LatestVersion: latestPackage.GetSemanticVersionString(),
+ TotalDownloads: downloads
);
}
);