WIP reg page

This commit is contained in:
Paul Schneider 2022-09-23 20:34:51 +01:00
commit fececb327e
36 changed files with 264 additions and 211 deletions

View file

@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using isn.Abstract;
using isnd.Controllers;
using isnd.Data;
using isnd.Data.Catalog;
using isnd.Data.Packages;
@ -119,16 +118,17 @@ namespace isnd.Services
Type = "RegistrationsBaseUrl/3.6.0",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
});
return res;
}
public PackageRegistrationIndexViewModel SearchByName(string query,
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.Versions)
.Include(p => p.Owner)
.Where(
p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query))
@ -137,12 +137,11 @@ namespace isnd.Services
);
var total = scope.Count();
var pkgs = scope.Skip(skip).Take(take).ToArray();
return new PackageRegistrationIndexViewModel
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}/";
var leaves = pkgs.Select(p => p.ToLeave(bid));
return new RegistrationPageIndex
{
Query = query,
TotalHits = total,
Data = pkgs.Select(p => p.ToLeave()).ToArray()
Items = leaves.CreateRegistrationPages(bid)
};
}
@ -187,6 +186,9 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get; protected set; }
public static List<Page> CurrentCatalogPages { get; protected set; }
public string CatalogBaseUrl => extUrl;
private IsndSettings isndSettings;
private string extUrl;
@ -320,7 +322,7 @@ namespace isnd.Services
v.Type == type
);
}
public IEnumerable<PackageVersion> GetCatalogLeaf(string id, string version, string lower)
{
return dbContext.PackageVersions
@ -329,5 +331,18 @@ namespace isnd.Services
.Where(v => v.PackageId == id && v.FullString == version
&& (lower == null || lower == v.Type));
}
public async Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string uid, string id, string lower, string type)
{
PackageVersion packageVersion = await dbContext.PackageVersions
.Include(pv => pv.Package)
.FirstOrDefaultAsync(m => m.PackageId == id
&& m.FullString == lower && m.Type == type);
if (packageVersion == null) return null;
if (packageVersion.Package.OwnerId != uid) return null;
return new PackageDeletionReport { Deleted = true, DeletedVersion = packageVersion };
}
}
}