diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..136a6e16 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,29 @@ +# Docker +# Build a Docker image +# https://docs.microsoft.com/azure/devops/pipelines/languages/docker + +trigger: +- main + +resources: +- repo: self + +variables: + tag: '$(Build.BuildId)' + +stages: +- stage: Build + displayName: Build image + jobs: + - job: Build + displayName: Build + pool: + vmImage: ubuntu-latest + steps: + - task: Docker@2 + displayName: Build an image + inputs: + command: build + dockerfile: '$(Build.SourcesDirectory)/.devcontainer/Dockerfile' + tags: | + $(tag) diff --git a/src/BaGet.Web/BaGetEndpointBuilder.cs b/src/BaGet.Web/BaGetEndpointBuilder.cs index d485eb40..8a187f20 100644 --- a/src/BaGet.Web/BaGetEndpointBuilder.cs +++ b/src/BaGet.Web/BaGetEndpointBuilder.cs @@ -17,6 +17,8 @@ public void MapEndpoints(IEndpointRouteBuilder endpoints) MapSearchRoutes(endpoints); MapPackageMetadataRoutes(endpoints); MapPackageContentRoutes(endpoints); + MapPackageVersionRoutes(endpoints); + } public void MapServiceIndexRoutes(IEndpointRouteBuilder endpoints) @@ -126,5 +128,13 @@ 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" }); + } } } diff --git a/src/BaGet.Web/Controllers/VersionsController.cs b/src/BaGet.Web/Controllers/VersionsController.cs new file mode 100644 index 00000000..b3930dcb --- /dev/null +++ b/src/BaGet.Web/Controllers/VersionsController.cs @@ -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>> 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); + } + } +} diff --git a/src/BaGet.Web/Dtos/VersionsDto.cs b/src/BaGet.Web/Dtos/VersionsDto.cs new file mode 100644 index 00000000..ec9ab303 --- /dev/null +++ b/src/BaGet.Web/Dtos/VersionsDto.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace BaGet.Web.Dtos +{ + public class VersionDto + { + public List versions { get; set; } = new List(); + } +}