Skip to content

Commit

Permalink
Fix primary key errors in pages after adding semver suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jun 21, 2024
1 parent e9a697f commit 6a9f1ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static string RenderList(IEnumerable<PackageSummary> summaries)
<tr>
<th scope=""col"">Name</th>
<th scope=""col"">Summary</th>
<th scope=""col"">Latest version</th>
<th scope=""col"">Latest stable version</th>
<th scope=""col"">Release date</th>
<th scope=""col"">Tags</th>
<th scope=""col"">Total Downloads</th>
Expand Down
27 changes: 9 additions & 18 deletions src/PackageRegistryService/Pages/Handlers/PackageHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@
using PackageRegistryService.Pages.Components;
using System.Text;
using System.Xml.Linq;
using static AVPRIndex.Domain;

namespace PackageRegistryService.Pages.Handlers
{
public static class PackageHandlers
{
public static async Task<Results<ContentHttpResult, NotFound, BadRequest<string>>> 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)
{
Expand Down Expand Up @@ -65,7 +56,7 @@ public static async Task<Results<ContentHttpResult, NotFound>> RenderLatest(stri
{
var packages = await
database.ValidationPackages
.Where(p => p.Name == packageName)
.Where(p => p.Name == packageName && p.BuildMetadataVersionSuffix == "" && p.BuildMetadataVersionSuffix == "")
.ToArrayAsync();

var latestPackage =
Expand All @@ -80,7 +71,7 @@ public static async Task<Results<ContentHttpResult, NotFound>> 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: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static async Task<ContentHttpResult> Render(ValidationPackageDb database)
var latestPackage =
group
.Where(p => p.BuildMetadataVersionSuffix == "" && p.BuildMetadataVersionSuffix == "")
.OrderByDescending(p => p.MajorVersion)
.ThenByDescending(p => p.MinorVersion)
.ThenByDescending(p => p.PatchVersion)
Expand Down

0 comments on commit 6a9f1ff

Please sign in to comment.