Versionning
This commit is contained in:
@ -17,9 +17,9 @@ namespace isn
|
|||||||
var resources = SourceHelpers.GetServerResources(source);
|
var resources = SourceHelpers.GetServerResources(source);
|
||||||
if (resources.Resources == null)
|
if (resources.Resources == null)
|
||||||
throw new InvalidOperationException("source gave no resource");
|
throw new InvalidOperationException("source gave no resource");
|
||||||
if (!resources.Resources.Any(res => res.Type == "PackagePublish/2.0.0"))
|
if (!resources.Resources.Any(res => res.Type == "PackagePublish/3.5.0"))
|
||||||
throw new InvalidOperationException("Source won't serve the expected push command");
|
throw new InvalidOperationException("Source won't serve the expected push command");
|
||||||
var pubRes = resources.Resources.First(res => res.Type == "PackagePublish/2.0.0");
|
var pubRes = resources.Resources.First(res => res.Type == "PackagePublish/3.5.0");
|
||||||
FileInfo fi = new FileInfo(pkg);
|
FileInfo fi = new FileInfo(pkg);
|
||||||
if (!fi.Exists)
|
if (!fi.Exists)
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using isnd.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace isnd.Controllers
|
namespace isnd.Controllers
|
||||||
@ -15,17 +16,22 @@ namespace isnd.Controllers
|
|||||||
int skip = 0,
|
int skip = 0,
|
||||||
int take = 25)
|
int take = 25)
|
||||||
{
|
{
|
||||||
if (take > maxTake)
|
CheckParams(take, semVerLevel);
|
||||||
{
|
if (ModelState.ErrorCount > 0) return BadRequest(ModelState);
|
||||||
ModelState.AddModelError("take", "Maximum exceeded");
|
|
||||||
return BadRequest(ModelState);
|
|
||||||
}
|
|
||||||
if (semVerLevel != defaultSemVer)
|
|
||||||
{
|
|
||||||
ModelState.AddModelError("semVerLevel", defaultSemVer + " expected");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(_packageManager.AutoComplete(id,skip,take,prerelease,packageType));
|
return Ok(_packageManager.AutoComplete(id,skip,take,prerelease,packageType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CheckParams(int take,string semVerLevel)
|
||||||
|
{
|
||||||
|
if (take > maxTake)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("take", "Maximum exceeded");
|
||||||
|
}
|
||||||
|
if (semVerLevel != PackageManager.BASE_API_LEVEL)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("semVerLevel", PackageManager.BASE_API_LEVEL + " expected");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,8 +23,6 @@ namespace isnd.Controllers
|
|||||||
public partial class PackagesController : Controller
|
public partial class PackagesController : Controller
|
||||||
{
|
{
|
||||||
const int maxTake = 100;
|
const int maxTake = 100;
|
||||||
|
|
||||||
const string defaultSemVer = "2.0.0";
|
|
||||||
private readonly Resource[] _resources;
|
private readonly Resource[] _resources;
|
||||||
private readonly ILogger<PackagesController> _logger;
|
private readonly ILogger<PackagesController> _logger;
|
||||||
private readonly IDataProtector _protector;
|
private readonly IDataProtector _protector;
|
||||||
@ -55,7 +53,7 @@ namespace isnd.Controllers
|
|||||||
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
|
[HttpGet(_pkgRootPrefix + ApiConfig.Base)]
|
||||||
public IActionResult ApiIndex()
|
public IActionResult ApiIndex()
|
||||||
{
|
{
|
||||||
return Ok(new ApiIndexViewModel{ Version = "3.0.0", Resources = _resources });
|
return Ok(new ApiIndexViewModel{ Version = PackageManager.BASE_API_LEVEL, Resources = _resources });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ namespace isnd.Services
|
|||||||
public class PackageManager : IPackageManager
|
public class PackageManager : IPackageManager
|
||||||
{
|
{
|
||||||
public const string BASE_API_LEVEL = "3.5.0";
|
public const string BASE_API_LEVEL = "3.5.0";
|
||||||
|
|
||||||
ApplicationDbContext dbContext;
|
ApplicationDbContext dbContext;
|
||||||
|
|
||||||
public PackageManager(ApplicationDbContext dbContext,
|
public PackageManager(ApplicationDbContext dbContext,
|
||||||
|
@ -69,7 +69,7 @@ dataTable.Rows.Add(dataRow);
|
|||||||
var model = await SourceHelpers.GetServerResourcesUsingWebRequestAsync("Http://isn.pschneider.fr/index.json");
|
var model = await SourceHelpers.GetServerResourcesUsingWebRequestAsync("Http://isn.pschneider.fr/index.json");
|
||||||
Console.WriteLine(JsonConvert.SerializeObject(model));
|
Console.WriteLine(JsonConvert.SerializeObject(model));
|
||||||
Assert.NotNull(model.Resources);
|
Assert.NotNull(model.Resources);
|
||||||
var pub = model.Resources.FirstOrDefault((r) => r.Type == "PackagePublish/2.0.0");
|
var pub = model.Resources.FirstOrDefault((r) => r.Type == "PackagePublish/3.5.0");
|
||||||
Assert.True(pub!=null);
|
Assert.True(pub!=null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user