This commit is contained in:
Paul Schneider 2021-08-23 03:21:08 +01:00
commit cdb9a26d2c
16 changed files with 301 additions and 59 deletions

View file

@ -10,15 +10,11 @@ using Microsoft.Extensions.Options;
using NuGet.Versioning;
using isnd.Data;
using isnd.Entities;
using Unleash.ClientFactory;
using Unleash;
using System.Collections.Generic;
using isnd.Services;
using isnd.Entities;
using Microsoft.AspNetCore.Hosting;
using isnd.Helpers;
using isnd.ViewModels;
using System.Threading.Tasks;
using isnd.Interfaces;
namespace isnd.Controllers
{
@ -36,7 +32,7 @@ namespace isnd.Controllers
private readonly IsndSettings _isndSettings;
readonly ApplicationDbContext _dbContext;
private readonly PackageManager _packageManager;
private readonly IPackageManager _packageManager;
private readonly IUnleash _unleashĈlient;
public PackagesController(
@ -44,13 +40,14 @@ namespace isnd.Controllers
IDataProtectionProvider provider,
IOptions<IsndSettings> isndOptions,
IUnleash unleashĈlient,
ApplicationDbContext dbContext)
ApplicationDbContext dbContext,
IPackageManager pm)
{
_logger = loggerFactory.CreateLogger<PackagesController>();
_isndSettings = isndOptions.Value;
_protector = provider.CreateProtector(_isndSettings.ProtectionTitle);
_dbContext = dbContext;
_packageManager = new PackageManager(dbContext);
_packageManager = pm;
_unleashĈlient = unleashĈlient;
_ressources = _packageManager.GetResources(_unleashĈlient).ToArray();
}
@ -104,33 +101,12 @@ namespace isnd.Controllers
return Ok(_ressources);
}
[HttpGet(_pkgRootPrefix + "/index.json")]
public IActionResult Index(
string q,
string semVerLevel,
bool prerelease = false,
string packageType = null,
int skip = 0,
int take = 25)
//
[HttpGet(_pkgRootPrefix)]
public IActionResult Index()
{
if (string.IsNullOrEmpty(q))
{
ModelState.AddModelError("q", "no value");
}
if (take > maxTake)
{
ModelState.AddModelError("take", "Maximum exceeded");
}
if (semVerLevel != defaultSemVer)
{
_logger.LogWarning("Unexpected sementic version : "+semVerLevel);
}
if (ModelState.IsValid)
{
return Ok(_packageManager.SearchByName(q,skip,take,prerelease,packageType));
}
return BadRequest(new { error = ModelState });
// https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning
return Ok(PackageManager.CurrentCatalogIndex);
}
// GET /autocomplete?id=isn.protocol&prerelease=true