From b6035bf42bcfae4d1eb01843cf470bc6a7f6c6a9 Mon Sep 17 00:00:00 2001 From: Amandio Ribeiro Date: Tue, 6 Dec 2022 15:25:54 +0000 Subject: [PATCH 1/2] Add v3-flatcontainer as in api.nuget.com --- src/BaGet.Web/BaGetEndpointBuilder.cs | 10 ++++++ .../Controllers/VersionsController.cs | 34 +++++++++++++++++++ src/BaGet.Web/Dtos/VersionsDto.cs | 9 +++++ 3 files changed, 53 insertions(+) create mode 100644 src/BaGet.Web/Controllers/VersionsController.cs create mode 100644 src/BaGet.Web/Dtos/VersionsDto.cs 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(); + } +} From 8974f64ff1263921776d3f77dd38369281348bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A2ndio=20Ribeiro?= Date: Tue, 6 Dec 2022 16:23:02 +0000 Subject: [PATCH 2/2] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 azure-pipelines.yml 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)