From c147eaf54af7123a3d45258eff09aff440d4f6c7 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 27 Sep 2022 00:39:17 +0100 Subject: [PATCH] by Nuget version --- src/isnd/Controllers/Packages/WebViews.cs | 4 +- .../PackageRegistrationIndexViewModel.cs | 21 ++++++--- src/isnd/Data/Catalog/RegistrationPage.cs | 1 + src/isnd/Data/Packages/Package.cs | 2 +- src/isnd/Data/Packages/PackageVersion.cs | 5 +- src/isnd/Interfaces/IPackageManager.cs | 2 +- src/isnd/Services/PackageManager.cs | 47 +++++++++---------- src/isnd/Views/Packages/Index.cshtml | 2 +- 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/isnd/Controllers/Packages/WebViews.cs b/src/isnd/Controllers/Packages/WebViews.cs index 0f6b97c..7c70e57 100644 --- a/src/isnd/Controllers/Packages/WebViews.cs +++ b/src/isnd/Controllers/Packages/WebViews.cs @@ -15,9 +15,9 @@ namespace isnd.Controllers public partial class PackagesController { // Web search - public async Task Index(PackageRegistrationIndexQuery model) + public async Task Index(RegistrationPageIndexQuery model) { - return View(packageManager.GetCatalogIndex()); + return View(packageManager.GetPackageRegistrationIndex(model)); } public async Task Details(string pkgid) diff --git a/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs b/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs index f528e35..772b820 100644 --- a/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs +++ b/src/isnd/Data/Catalog/PackageRegistrationIndexViewModel.cs @@ -1,20 +1,27 @@ +using System.Collections.Generic; using Newtonsoft.Json; namespace isnd.Data.Catalog { - public class PackageRegistrationIndexQuery : RegistrationPageIndex + public class RegistrationPageIndexQuery : RegistrationPageIndex { - public PackageRegistrationIndexQuery(string id) : base(id) + + public RegistrationPageIndexQuery() : base("") + { + } + public RegistrationPageIndexQuery(string bid, IEnumerable leaves) : base(bid, leaves) { } - - [JsonProperty("prerelease")] - public bool Prerelease { get; set; } [JsonProperty("query")] public string Query { get; set; } - [JsonProperty("totalHits")] - public int TotalHits { get; internal set; } + [JsonProperty("prerelease")] + public bool Prerelease { get; set; } + + public int Skip { get; set; } + + public int Take { get; set; } = 25; + public int TotalHits { get; set; } } } \ No newline at end of file diff --git a/src/isnd/Data/Catalog/RegistrationPage.cs b/src/isnd/Data/Catalog/RegistrationPage.cs index 66ac9c4..6db4728 100644 --- a/src/isnd/Data/Catalog/RegistrationPage.cs +++ b/src/isnd/Data/Catalog/RegistrationPage.cs @@ -12,6 +12,7 @@ namespace isnd.Data.Catalog public RegistrationPage (string id) { Id = id; + Items = new List(); } /// diff --git a/src/isnd/Data/Packages/Package.cs b/src/isnd/Data/Packages/Package.cs index 85f0161..a33f74f 100644 --- a/src/isnd/Data/Packages/Package.cs +++ b/src/isnd/Data/Packages/Package.cs @@ -54,7 +54,7 @@ namespace isnd.Data.Packages public RegistrationLeaf ToLeave(string bid) { if (Versions.Count == 0) throw new Exception("NO VERSION"); - var v = Versions.OrderBy(w => w.SystemVersion).First(); + var v = Versions.OrderBy(w => w.NugetVersion).First(); RegistrationLeaf leave = new RegistrationLeaf { Id = bid + Id + "/" + v.FullString + ".json", diff --git a/src/isnd/Data/Packages/PackageVersion.cs b/src/isnd/Data/Packages/PackageVersion.cs index 53e4207..9415ebc 100644 --- a/src/isnd/Data/Packages/PackageVersion.cs +++ b/src/isnd/Data/Packages/PackageVersion.cs @@ -1,10 +1,11 @@ -using System; + using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using isn.abst; using isnd.Data.Packages; using isnd.Data.Packages.Catalog; using Newtonsoft.Json; +using NuGet.Versioning; namespace isnd.Data { @@ -53,7 +54,7 @@ namespace isnd.Data + Constants.SpecFileEstension; public string SementicVersionString { get => $"{Major}.{Minor}.{Patch}"; } - public Version SystemVersion { get => new Version(Major, Minor, Patch, Revision); } + public NuGetVersion NugetVersion { get => new NuGetVersion(FullString); } } } \ No newline at end of file diff --git a/src/isnd/Interfaces/IPackageManager.cs b/src/isnd/Interfaces/IPackageManager.cs index dc112c0..f091819 100644 --- a/src/isnd/Interfaces/IPackageManager.cs +++ b/src/isnd/Interfaces/IPackageManager.cs @@ -19,7 +19,6 @@ namespace isnd.Interfaces AutoCompleteResult AutoComplete(string pkgid, int skip, int take, bool prerelease = false, string packageType = null); string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25); - RegistrationPageIndex SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null); IEnumerable GetResources(IUnleash unleashĈlient); void ÛpdateCatalogFor(Commit commit); Task DeletePackageAsync(string pkgid, string version, string type); @@ -29,6 +28,7 @@ namespace isnd.Interfaces IEnumerable SearchById(string pkgId, string semver, string pkgType); RegistrationPageIndex GetCatalogIndex(); + RegistrationPageIndexQuery GetPackageRegistrationIndex(RegistrationPageIndexQuery query); } } \ No newline at end of file diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index c78ba98..07b2b8e 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -122,27 +122,6 @@ namespace isnd.Services return res; } - public RegistrationPageIndex SearchByName(string query, - int skip, int take, bool prerelease = false, - string packageType = null) - { - - var scope = dbContext.Packages - .Include(p => p.Versions) - .Include(p => p.Owner) - .Where( - p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query)) - && (prerelease || p.Versions.Any(v => !v.IsPrerelease)) - && (packageType == null || p.Versions.Any(v => v.Type == packageType)) - ); - var total = scope.Count(); - var pkgs = scope.Skip(skip).Take(take).ToArray(); - string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/"; - var leaves = pkgs.Select(p => p.ToLeave(bid)); - - return new RegistrationPageIndex(bid, leaves); - } - public AutoCompleteResult AutoComplete(string id, int skip, int take, bool prerelease = false, string packageType = null) @@ -177,7 +156,7 @@ namespace isnd.Services && (packageType == null || v.Type == packageType) && (parsedVersion.CompareTo(new SemanticVersion(v.Major, v.Minor, v.Patch)) < 0) ) - .OrderBy(v => v.FullString) + .OrderBy(v => v.NugetVersion) .Select(v => v.FullString) .Skip(skip).Take(take).ToArray(); } @@ -234,6 +213,7 @@ namespace isnd.Services i = 0; } var validPkgs = dbContext.Packages + .Include(po => po.Owner) .Include(pkg => pkg.Versions) .Include(pkg => pkg.LatestVersion) .Where( @@ -319,8 +299,6 @@ namespace isnd.Services && (pkgType == null || pkgType == v.Type)); } - - public async Task UserAskForPackageDeletionAsync(string uid, string id, string lower, string type) { PackageVersion packageVersion = await dbContext.PackageVersions @@ -337,6 +315,7 @@ namespace isnd.Services string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/"; return dbContext.PackageVersions .Include(v => v.Package) + .Include(v => v.Package.Owner) .Include(v => v.LatestCommit) .Where(v => v.PackageId == pkgId && semver.StartsWith(v.SementicVersionString) && (pkgType == null || pkgType == v.Type)).Select(p => p.Package.ToLeave(bid)); @@ -349,5 +328,25 @@ namespace isnd.Services .Single(v => v.PackageId == pkgId && semver == v.FullString && (pkgType == null || pkgType == v.Type)); } + + public RegistrationPageIndexQuery GetPackageRegistrationIndex(RegistrationPageIndexQuery query) + { + // RegistrationPageIndexAndQuery + var scope = dbContext.Packages + .Include(p => p.Versions) + .Include(p => p.Owner) + .Where( + p => (PackageIdHelpers.CamelCaseMatch(p.Id, query.Query) + || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query.Query)) + && (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease)) + ); + var total = scope.Count(); + var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray(); + string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/"; + var leaves = pkgs.Select(p => p.ToLeave(bid)); + + return + new RegistrationPageIndexQuery(bid, leaves); + } } } \ No newline at end of file diff --git a/src/isnd/Views/Packages/Index.cshtml b/src/isnd/Views/Packages/Index.cshtml index 1d8d4c6..2b85c99 100644 --- a/src/isnd/Views/Packages/Index.cshtml +++ b/src/isnd/Views/Packages/Index.cshtml @@ -1,4 +1,4 @@ -@model PackageRegistrationIndexQuery +@model RegistrationPageIndexQuery @{ ViewData["Title"] = "Index";