A valid package index page

This commit is contained in:
Paul Schneider 2022-10-15 18:26:55 +01:00
commit 58f77a06ea
15 changed files with 210 additions and 153 deletions

View file

@ -24,28 +24,32 @@ namespace isnd.Controllers
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
}
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/index.json")]
public async Task<IActionResult> CatalogRegistrationAsync(string apiVersion, string id)
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
public IActionResult CatalogRegistration(string apiVersion, string id, string lower)
{
var pkgs = packageManager.SearchById(id, null, null);
if (pkgs == null) return NotFound();
return Ok(pkgs);
if (lower.Equals("index", System.StringComparison.OrdinalIgnoreCase))
{
var query = new Data.Catalog.RegistrationPageIndexQuery
{
Query = id,
Prerelease = true
};
var index = packageManager.GetPackageRegistrationIndex(query);
if (index == null) return NotFound();
// query.TotalHits = result.Items.Select(i=>i.Items.Length).Aggregate((a,b)=>a+b);
return Ok(index);
}
var leaf = packageManager.SearchById(id,lower,null);
if (leaf.Count()==0) return NotFound(new { id, lower });
return Ok(leaf.First());
}
[HttpGet(_pkgRootPrefix + ApiConfig.CatalogLeaf + "/{id}/{version}/{lower}/index.json")]
public async Task<IActionResult> CatalogLeafAsync(string id, string pversion, string lower)
public IActionResult CatalogLeaf(string id, string pversion, string lower)
{
bool askForindex = lower == null;
if (false)
{
if (!NuGetVersion.TryParse(lower, out NuGetVersion version))
return BadRequest(lower);
var pkgFromname = packageManager.GetVersions(id, version, true);
if (pkgFromname == null) return NotFound();
return Ok(pkgFromname);
}
var pkgvs = this.packageManager.GetCatalogLeaf(id, pversion, lower).ToArray();
if (pkgvs.Count() == 0) return NotFound();
List<string> types = pkgvs.Select(

View file

@ -0,0 +1,10 @@
using isnd.Data.Catalog;
namespace isnd
{
public class RegistrationPageIndexQueryAndResult
{
public RegistrationPageIndexQuery Query { get; set; }
public RegistrationPageIndex Result { get; set; }
}
}

View file

@ -11,7 +11,7 @@ namespace isnd.Controllers
{
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
[HttpGet(_pkgRootPrefix + ApiConfig.Search)]
public async Task<IActionResult> Search(
public IActionResult Search(
string q,
int skip = 0,
int take = 25,

View file

@ -17,7 +17,8 @@ namespace isnd.Controllers
// Web search
public async Task<IActionResult> Index(RegistrationPageIndexQuery model)
{
return View(packageManager.GetPackageRegistrationIndex(model));
return View(new RegistrationPageIndexQueryAndResult{Query = model,
Result = packageManager.GetPackageRegistrationIndex(model)});
}
public async Task<IActionResult> Details(string pkgid)