Skip to content

Commit

Permalink
Add v3-flatcontainer as in api.nuget.com. Merge PR: loic-sharma#752
Browse files Browse the repository at this point in the history
  • Loading branch information
VAllens committed Aug 31, 2023
1 parent 15239f0 commit 7959ecd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/BaGet.Web/BaGetEndpointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void MapEndpoints(IEndpointRouteBuilder endpoints)
MapSearchRoutes(endpoints);
MapPackageMetadataRoutes(endpoints);
MapPackageContentRoutes(endpoints);
MapPackageVersionRoutes(endpoints);
}

public void MapServiceIndexRoutes(IEndpointRouteBuilder endpoints)
Expand Down Expand Up @@ -121,4 +122,12 @@ public void MapPackageContentRoutes(IEndpointRouteBuilder endpoints)
pattern: "v3/package/{id}/{version}/icon",
defaults: new { controller = "PackageContent", action = "DownloadIcon" });
}

public void MapPackageVersionRoutes(IEndpointRouteBuilder endpoints)
{
endpoints.MapControllerRoute(
name: Routes.PackageVersionsRouteName,
pattern: "v3-flatcontainer/{packageId}/index.json",
defaults: new { controller = "VersionsController", action = "GetVersionsForPackage" });
}
}
34 changes: 34 additions & 0 deletions src/BaGet.Web/Controllers/VersionsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using BaGet.Core;
using BaGet.Web.Dtos;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.Linq;

namespace BaGet.Web.Controllers
{
[Route("v3-flatcontainer/{packageId}/index.json")]
[ApiController]
public class VersionsController : ControllerBase
{
private readonly IPackageDatabase _packageDatabase;
public VersionsController(IPackageDatabase packageDatabase)
{
_packageDatabase = packageDatabase;
}

[HttpGet]
public async Task<ActionResult<IEnumerable<string>>> GetVersionsForPackage(string packageId)
{
Console.WriteLine($"--> Getting versions for package {packageId} from Automaise nuget");
var exists = await _packageDatabase.ExistsAsync(packageId, new System.Threading.CancellationToken());
if (!exists)
return NotFound();
var retVersions = await _packageDatabase.FindAsync(packageId, true, new System.Threading.CancellationToken());
var versionDto = new VersionDto();
versionDto.versions = retVersions.Select(x => x.Version.ToString()).ToList();
return Ok(versionDto);
}
}
}
9 changes: 9 additions & 0 deletions src/BaGet.Web/Dtos/VersionsDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace BaGet.Web.Dtos
{
public class VersionDto
{
public List<string> versions { get; set; } = new List<string>();
}
}

0 comments on commit 7959ecd

Please sign in to comment.