From 6a9f1fff53735713ed57fdf93818178678c53568 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 21 Jun 2024 13:21:27 +0200 Subject: [PATCH] Fix primary key errors in pages after adding semver suffixes --- .../Pages/Components/PackageSummary.cs | 2 +- .../Pages/Handlers/PackageHandlers.cs | 27 +++++++------------ .../Pages/Handlers/PackagesHandlers.cs | 1 + 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/PackageRegistryService/Pages/Components/PackageSummary.cs b/src/PackageRegistryService/Pages/Components/PackageSummary.cs index 667b592..00ddbce 100644 --- a/src/PackageRegistryService/Pages/Components/PackageSummary.cs +++ b/src/PackageRegistryService/Pages/Components/PackageSummary.cs @@ -25,7 +25,7 @@ public static string RenderList(IEnumerable summaries) Name Summary -Latest version +Latest stable version Release date Tags Total Downloads diff --git a/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs b/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs index 6ff5523..75d1c83 100644 --- a/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs +++ b/src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs @@ -4,6 +4,7 @@ using PackageRegistryService.Pages.Components; using System.Text; using System.Xml.Linq; +using static AVPRIndex.Domain; namespace PackageRegistryService.Pages.Handlers { @@ -11,25 +12,15 @@ public static class PackageHandlers { public static async Task>> Render(string packageName, string version, ValidationPackageDb database) { - var splt = version.Split('.'); - if (splt.Length != 3) + var semVerOpt = SemVer.tryParse(version); + if (semVerOpt is null) { - return TypedResults.BadRequest("version was not a of valid format MAJOR.MINOR.REVISION"); + return TypedResults.BadRequest($"{version} is not a valid semantic version."); } + var semVer = semVerOpt.Value; - int major; int minor; int revision; - - if ( - !int.TryParse(splt[0], out major) - || !int.TryParse(splt[1], out minor) - || !int.TryParse(splt[2], out revision) - ) - { - return TypedResults.BadRequest("version was not a of valid format MAJOR.MINOR.REVISION"); - } - - var package = await database.ValidationPackages.FindAsync(packageName, major, minor, revision); - var downloads = await database.Downloads.FindAsync(packageName, major, minor, revision); + var package = await database.ValidationPackages.FindAsync(packageName, semVer.Major, semVer.Minor, semVer.Patch, semVer.PreRelease, semVer.BuildMetadata); + var downloads = await database.Downloads.FindAsync(packageName, semVer.Major, semVer.Minor, semVer.Patch, semVer.PreRelease, semVer.BuildMetadata); if (package == null) { @@ -65,7 +56,7 @@ public static async Task> RenderLatest(stri { var packages = await database.ValidationPackages - .Where(p => p.Name == packageName) + .Where(p => p.Name == packageName && p.BuildMetadataVersionSuffix == "" && p.BuildMetadataVersionSuffix == "") .ToArrayAsync(); var latestPackage = @@ -80,7 +71,7 @@ public static async Task> RenderLatest(stri return TypedResults.NotFound(); } - var downloads = await database.Downloads.FindAsync(latestPackage.Name, latestPackage.MajorVersion, latestPackage.MinorVersion, latestPackage.PatchVersion); + var downloads = await database.Downloads.FindAsync(latestPackage.Name, latestPackage.MajorVersion, latestPackage.MinorVersion, latestPackage.PatchVersion, latestPackage.PreReleaseVersionSuffix, latestPackage.BuildMetadataVersionSuffix); var page = Layout.Render( activeNavbarItem: "", diff --git a/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs b/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs index 2c0168b..375bfcc 100644 --- a/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs +++ b/src/PackageRegistryService/Pages/Handlers/PackagesHandlers.cs @@ -35,6 +35,7 @@ public static async Task Render(ValidationPackageDb database) var latestPackage = group + .Where(p => p.BuildMetadataVersionSuffix == "" && p.BuildMetadataVersionSuffix == "") .OrderByDescending(p => p.MajorVersion) .ThenByDescending(p => p.MinorVersion) .ThenByDescending(p => p.PatchVersion)