From f6fa7a0ec95a208a0d7363e260cd4b353fe245e2 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 28 Aug 2021 18:41:22 +0100 Subject: [PATCH] unit tests and pkg version commits --- .vscode/settings.json | 3 +- src/isn/isn.csproj | 2 +- src/isnd/Controllers/HomeController.cs | 6 +- .../Controllers/PackagesController.Put.cs | 10 +- src/isnd/Data/Catalog/Commit.cs | 20 +- src/isnd/Data/Catalog/PackageRef.cs | 4 + src/isnd/Data/Package.cs | 16 +- src/isnd/Data/PackageVersion.cs | 11 + ... 20210828142245_versionCommit.Designer.cs} | 21 +- ...ion.cs => 20210828142245_versionCommit.cs} | 46 ++- ...0210828150712_pkgVersionCommit.Designer.cs | 355 ++++++++++++++++++ .../20210828150712_pkgVersionCommit.cs | 44 +++ .../ApplicationDbContextModelSnapshot.cs | 26 +- src/isnd/Services/PackageManager.cs | 62 +-- src/isnd/Startup.cs | 5 - test/isn.tests/isn.tests.csproj | 3 +- test/isnd.tests/isnd.tests.csproj | 8 +- 17 files changed, 553 insertions(+), 89 deletions(-) rename src/isnd/Migrations/{20210827201859_commitVersion.Designer.cs => 20210828142245_versionCommit.Designer.cs} (96%) rename src/isnd/Migrations/{20210827201859_commitVersion.cs => 20210828142245_versionCommit.cs} (62%) create mode 100644 src/isnd/Migrations/20210828150712_pkgVersionCommit.Designer.cs create mode 100644 src/isnd/Migrations/20210828150712_pkgVersionCommit.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index 47e2fe9..54a8922 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "dotnet-test-explorer.runInParallel": false, "dotnet-test-explorer.showCodeLens": true, "dotnet-test-explorer.testArguments": "", - "nxunitExplorer.nunit": "" + "nxunitExplorer.nunit": "${workspaceFolder}/packages/nunit3-console.1.0.0/lib/net20/nunit3-console.exe", + "nxunitExplorer.xunit": "${workspaceFolder}/packages/xunit.runner.console.2.4.1/tools/net472/xunit.console.exe" } \ No newline at end of file diff --git a/src/isn/isn.csproj b/src/isn/isn.csproj index e11d38f..24b526b 100644 --- a/src/isn/isn.csproj +++ b/src/isn/isn.csproj @@ -1,7 +1,7 @@  Exe - net472 + netcoreapp2.1 nuget_cli 45b74c62-05bc-4603-95b4-3e80ae2fdf50 1.0.1 diff --git a/src/isnd/Controllers/HomeController.cs b/src/isnd/Controllers/HomeController.cs index 4537075..a1c9f22 100644 --- a/src/isnd/Controllers/HomeController.cs +++ b/src/isnd/Controllers/HomeController.cs @@ -10,17 +10,13 @@ namespace isnd.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; private readonly ApplicationDbContext _dbContext; - private readonly IHostingEnvironment _env; private readonly IUnleash _unleashĈlient; public HomeController( ApplicationDbContext dbContext, - IUnleash unleashĈlient, - ILogger logger) + IUnleash unleashĈlient) { - _logger = logger; _dbContext = dbContext; _unleashĈlient = unleashĈlient; } diff --git a/src/isnd/Controllers/PackagesController.Put.cs b/src/isnd/Controllers/PackagesController.Put.cs index 7be8a5f..69b71e9 100644 --- a/src/isnd/Controllers/PackagesController.Put.cs +++ b/src/isnd/Controllers/PackagesController.Put.cs @@ -14,6 +14,7 @@ using NuGet.Versioning; using isnd.Data; using isnd.Helpers; using Microsoft.AspNetCore.Http; +using isnd.Data.Catalog; namespace isnd.Controllers { @@ -39,6 +40,12 @@ namespace isnd.Controllers _logger.LogError("403 : no api-key"); return Unauthorized(); } + Commit commit = new Commit + { + Action = PackageAction.PublishPackage, + TimeStamp = DateTime.Now + }; + _dbContext.Commits.Add(commit); foreach (IFormFile file in Request.Form.Files) { @@ -93,7 +100,8 @@ namespace isnd.Controllers { Id = pkgid, Description = pkgdesc, - OwnerId = apikey.UserId + OwnerId = apikey.UserId, + LatestVersion = commit }; _dbContext.Packages.Add(package); } diff --git a/src/isnd/Data/Catalog/Commit.cs b/src/isnd/Data/Catalog/Commit.cs index ce23269..594a42b 100644 --- a/src/isnd/Data/Catalog/Commit.cs +++ b/src/isnd/Data/Catalog/Commit.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; namespace isnd.Data.Catalog { @@ -12,21 +14,25 @@ namespace isnd.Data.Catalog public class Commit : IObject { - [Key][Required,DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, + DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [JsonIgnore] public long Id { get; set; } - [Required] + [Required][JsonIgnore] public DateTime TimeStamp{ get; set; } [Required] public PackageAction Action { get; set; } - [Required] - public string PackageVersionId { get; set; } - [ForeignKey("PackageVersionId")] - - public virtual PackageVersion PackageVersion{ get; set; } + [NotMapped] public string CommitId { get => Id.ToString(); } + + [NotMapped] public DateTime CommitTimeStamp { get => TimeStamp; } + + [ForeignKey("CommitNId")] + + public virtual List Versions { get; set; } } } \ No newline at end of file diff --git a/src/isnd/Data/Catalog/PackageRef.cs b/src/isnd/Data/Catalog/PackageRef.cs index 77ea023..8dd3171 100644 --- a/src/isnd/Data/Catalog/PackageRef.cs +++ b/src/isnd/Data/Catalog/PackageRef.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; namespace isnd.Data.Catalog @@ -38,6 +39,9 @@ namespace isnd.Data.Catalog [JsonProperty("nuget:version")] public string Version { get; set; } public string CommitId { get; set; } + + [ForeignKey("CommitId")] + public virtual Commit LastCommit { get; set; } public DateTime CommitTimeStamp { get; set; } } } \ No newline at end of file diff --git a/src/isnd/Data/Package.cs b/src/isnd/Data/Package.cs index 0470821..21d05ba 100644 --- a/src/isnd/Data/Package.cs +++ b/src/isnd/Data/Package.cs @@ -27,7 +27,21 @@ namespace isnd.Data [JsonIgnore] public virtual List Versions { get; set; } - public string CommitId { get; set; } + + /// + /// Latest package version put, or post, + /// or { delete when no more active version }. + /// + /// + [Required][JsonIgnore] + public long CommitNId { get; set ; } + + [NotMapped] + public string CommitId { get => CommitNId.ToString(); } + + [ForeignKey("CommitNId")] + + public virtual Commit LatestVersion{ get; set; } public DateTime CommitTimeStamp { get; set; } } } \ No newline at end of file diff --git a/src/isnd/Data/PackageVersion.cs b/src/isnd/Data/PackageVersion.cs index 5888694..0355706 100644 --- a/src/isnd/Data/PackageVersion.cs +++ b/src/isnd/Data/PackageVersion.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using isnd.Data.Catalog; using Newtonsoft.Json; namespace isnd.Data @@ -30,6 +31,16 @@ namespace isnd.Data [JsonIgnore] public virtual Package Package { get; set; } + [Required][JsonIgnore] + public long CommitNId { get; set ; } + + [NotMapped] + + public string CommitId { get => CommitNId.ToString(); } + + [ForeignKey("CommitNId")] + + public virtual Commit LatestCommit{ get; set; } public string NugetLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nupkg"; public string NuspecLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nuspec"; diff --git a/src/isnd/Migrations/20210827201859_commitVersion.Designer.cs b/src/isnd/Migrations/20210828142245_versionCommit.Designer.cs similarity index 96% rename from src/isnd/Migrations/20210827201859_commitVersion.Designer.cs rename to src/isnd/Migrations/20210828142245_versionCommit.Designer.cs index 54b77dc..88ab4d4 100644 --- a/src/isnd/Migrations/20210827201859_commitVersion.Designer.cs +++ b/src/isnd/Migrations/20210828142245_versionCommit.Designer.cs @@ -10,8 +10,8 @@ using isnd.Data; namespace isndhost.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20210827201859_commitVersion")] - partial class commitVersion + [Migration("20210828142245_versionCommit")] + partial class versionCommit { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -208,15 +208,13 @@ namespace isndhost.Migrations b.Property("Action"); - b.Property("PackageId") + b.Property("PackageVersionId") .IsRequired(); b.Property("TimeStamp"); b.HasKey("Id"); - b.HasIndex("PackageId"); - b.ToTable("Commits"); }); @@ -225,7 +223,7 @@ namespace isndhost.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("CommitId"); + b.Property("CommitNId"); b.Property("CommitTimeStamp"); @@ -239,6 +237,8 @@ namespace isndhost.Migrations b.HasKey("Id"); + b.HasIndex("CommitNId"); + b.HasIndex("OwnerId"); b.ToTable("Packages"); @@ -320,16 +320,13 @@ namespace isndhost.Migrations .OnDelete(DeleteBehavior.Cascade); }); - modelBuilder.Entity("isnd.Data.Catalog.Commit", b => + modelBuilder.Entity("isnd.Data.Package", b => { - b.HasOne("isnd.Data.Package", "Package") + b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit") .WithMany() - .HasForeignKey("PackageId") + .HasForeignKey("CommitNId") .OnDelete(DeleteBehavior.Cascade); - }); - modelBuilder.Entity("isnd.Data.Package", b => - { b.HasOne("isnd.Data.ApplicationUser", "Owner") .WithMany() .HasForeignKey("OwnerId") diff --git a/src/isnd/Migrations/20210827201859_commitVersion.cs b/src/isnd/Migrations/20210828142245_versionCommit.cs similarity index 62% rename from src/isnd/Migrations/20210827201859_commitVersion.cs rename to src/isnd/Migrations/20210828142245_versionCommit.cs index 9641a64..97dc46e 100644 --- a/src/isnd/Migrations/20210827201859_commitVersion.cs +++ b/src/isnd/Migrations/20210828142245_versionCommit.cs @@ -4,14 +4,15 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace isndhost.Migrations { - public partial class commitVersion : Migration + public partial class versionCommit : Migration { protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( - name: "CommitId", + migrationBuilder.AddColumn( + name: "CommitNId", table: "Packages", - nullable: true); + nullable: false, + defaultValue: 0L); migrationBuilder.AddColumn( name: "CommitTimeStamp", @@ -33,32 +34,47 @@ namespace isndhost.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), TimeStamp = table.Column(nullable: false), Action = table.Column(nullable: false), - PackageId = table.Column(nullable: false) + PackageVersionId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Commits", x => x.Id); - table.ForeignKey( - name: "FK_Commits_Packages_PackageId", - column: x => x.PackageId, - principalTable: "Packages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); }); + migrationBuilder.Sql( + @"delete from 'PackageVersions'; delete from 'Packages';" + ); + + migrationBuilder.CreateIndex( - name: "IX_Commits_PackageId", - table: "Commits", - column: "PackageId"); + name: "IX_Packages_CommitNId", + table: "Packages", + column: "CommitNId"); + + migrationBuilder.AddForeignKey( + name: "FK_Packages_Commits_CommitNId", + table: "Packages", + column: "CommitNId", + principalTable: "Commits", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); } protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropForeignKey( + name: "FK_Packages_Commits_CommitNId", + table: "Packages"); + migrationBuilder.DropTable( name: "Commits"); + migrationBuilder.DropIndex( + name: "IX_Packages_CommitNId", + table: "Packages"); + migrationBuilder.DropColumn( - name: "CommitId", + name: "CommitNId", table: "Packages"); migrationBuilder.DropColumn( diff --git a/src/isnd/Migrations/20210828150712_pkgVersionCommit.Designer.cs b/src/isnd/Migrations/20210828150712_pkgVersionCommit.Designer.cs new file mode 100644 index 0000000..d04f09c --- /dev/null +++ b/src/isnd/Migrations/20210828150712_pkgVersionCommit.Designer.cs @@ -0,0 +1,355 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using isnd.Data; + +namespace isndhost.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210828150712_pkgVersionCommit")] + partial class pkgVersionCommit + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CreationDate"); + + b.Property("Name"); + + b.Property("UserId") + .IsRequired(); + + b.Property("ValidityPeriodInDays"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("isnd.Data.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("FullName"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("isnd.Data.Catalog.Commit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Action"); + + b.Property("PackageVersionId") + .IsRequired(); + + b.Property("TimeStamp"); + + b.HasKey("Id"); + + b.ToTable("Commits"); + }); + + modelBuilder.Entity("isnd.Data.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CommitNId"); + + b.Property("CommitTimeStamp"); + + b.Property("Description") + .HasMaxLength(1024); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("Public"); + + b.HasKey("Id"); + + b.HasIndex("CommitNId"); + + b.HasIndex("OwnerId"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("isnd.Data.PackageVersion", b => + { + b.Property("PackageId"); + + b.Property("FullString") + .HasMaxLength(256); + + b.Property("Type") + .HasMaxLength(256); + + b.Property("CommitNId"); + + b.Property("IsPrerelease"); + + b.Property("Major"); + + b.Property("Minor"); + + b.Property("Patch"); + + b.HasKey("PackageId", "FullString", "Type"); + + b.HasIndex("CommitNId"); + + b.ToTable("PackageVersions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b => + { + b.HasOne("isnd.Data.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.Package", b => + { + b.HasOne("isnd.Data.Catalog.Commit", "LatestVersion") + .WithMany() + .HasForeignKey("CommitNId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.ApplicationUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.PackageVersion", b => + { + b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit") + .WithMany() + .HasForeignKey("CommitNId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.Package", "Package") + .WithMany("Versions") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/isnd/Migrations/20210828150712_pkgVersionCommit.cs b/src/isnd/Migrations/20210828150712_pkgVersionCommit.cs new file mode 100644 index 0000000..821d8a3 --- /dev/null +++ b/src/isnd/Migrations/20210828150712_pkgVersionCommit.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace isndhost.Migrations +{ + public partial class pkgVersionCommit : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CommitNId", + table: "PackageVersions", + nullable: false, + defaultValue: 0L); + + migrationBuilder.CreateIndex( + name: "IX_PackageVersions_CommitNId", + table: "PackageVersions", + column: "CommitNId"); + + migrationBuilder.AddForeignKey( + name: "FK_PackageVersions_Commits_CommitNId", + table: "PackageVersions", + column: "CommitNId", + principalTable: "Commits", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_PackageVersions_Commits_CommitNId", + table: "PackageVersions"); + + migrationBuilder.DropIndex( + name: "IX_PackageVersions_CommitNId", + table: "PackageVersions"); + + migrationBuilder.DropColumn( + name: "CommitNId", + table: "PackageVersions"); + } + } +} diff --git a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs index c516ea3..8d885af 100644 --- a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs @@ -206,15 +206,13 @@ namespace isndhost.Migrations b.Property("Action"); - b.Property("PackageId") + b.Property("PackageVersionId") .IsRequired(); b.Property("TimeStamp"); b.HasKey("Id"); - b.HasIndex("PackageId"); - b.ToTable("Commits"); }); @@ -223,7 +221,7 @@ namespace isndhost.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("CommitId"); + b.Property("CommitNId"); b.Property("CommitTimeStamp"); @@ -237,6 +235,8 @@ namespace isndhost.Migrations b.HasKey("Id"); + b.HasIndex("CommitNId"); + b.HasIndex("OwnerId"); b.ToTable("Packages"); @@ -252,6 +252,8 @@ namespace isndhost.Migrations b.Property("Type") .HasMaxLength(256); + b.Property("CommitNId"); + b.Property("IsPrerelease"); b.Property("Major"); @@ -262,6 +264,8 @@ namespace isndhost.Migrations b.HasKey("PackageId", "FullString", "Type"); + b.HasIndex("CommitNId"); + b.ToTable("PackageVersions"); }); @@ -318,16 +322,13 @@ namespace isndhost.Migrations .OnDelete(DeleteBehavior.Cascade); }); - modelBuilder.Entity("isnd.Data.Catalog.Commit", b => + modelBuilder.Entity("isnd.Data.Package", b => { - b.HasOne("isnd.Data.Package", "Package") + b.HasOne("isnd.Data.Catalog.Commit", "LatestVersion") .WithMany() - .HasForeignKey("PackageId") + .HasForeignKey("CommitNId") .OnDelete(DeleteBehavior.Cascade); - }); - modelBuilder.Entity("isnd.Data.Package", b => - { b.HasOne("isnd.Data.ApplicationUser", "Owner") .WithMany() .HasForeignKey("OwnerId") @@ -336,6 +337,11 @@ namespace isndhost.Migrations modelBuilder.Entity("isnd.Data.PackageVersion", b => { + b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit") + .WithMany() + .HasForeignKey("CommitNId") + .OnDelete(DeleteBehavior.Cascade); + b.HasOne("isnd.Data.Package", "Package") .WithMany("Versions") .HasForeignKey("PackageId") diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index e0cfd86..7d6214e 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -14,12 +14,12 @@ using Unleash; namespace isnd.Services { - + public class PackageManager : IPackageManager { ApplicationDbContext dbContext; - public PackageManager(ApplicationDbContext dbContext, + public PackageManager(ApplicationDbContext dbContext, IOptions siteConfigOptionsOptions) { this.dbContext = dbContext; @@ -55,10 +55,6 @@ namespace isnd.Services public CatalogIndex GenerateCatalogIndex(string commitId) { - - var root = "/index.json"; - - var catalog = new CatalogIndex { CommitId = commitId, @@ -155,13 +151,13 @@ namespace isnd.Services } void LoadCatalogFromDb() { - int i=0; - int p=0; + int i = 0; + int p = 0; var oldIndex = CurrentCatalogIndex; var oldPages = CurrentCatalogPages; CurrentCatalogIndex = new CatalogIndex { - + }; CurrentCatalogPages = new List(); @@ -169,46 +165,60 @@ namespace isnd.Services Commit last = null; PageRef pageRef = null; Page page = null; - i=pmConfigOptions.CatalogPageLen; + i = pmConfigOptions.CatalogPageLen; foreach (var commit in scope) { if (i >= this.pmConfigOptions.CatalogPageLen) { - page = new Page{ - Parent = pmConfigOptions.ExternalUrl + "/package", + page = new Page + { + Parent = pmConfigOptions.ExternalUrl + "/package", CommitId = commit.CommitId, CommitTimeStamp = commit.CommitTimeStamp, Id = this.pmConfigOptions.ExternalUrl + "/package/index-" + p++ }; CurrentCatalogPages.Add(page); - pageRef = new PageRef{ - Id = page.Id + pageRef = new PageRef + { + Id = page.Id }; CurrentCatalogIndex.Items.Add(pageRef); i = 0; } - PackageRef packageref = new PackageRef + var validPkgs = dbContext.Packages + .Include(pkg => pkg.Versions) + .Where( + pkg => pkg.Versions.Count() > 0 + ); + // pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString + foreach (var pkg in validPkgs) { - CommitId = commit.Id.ToString(), - Id = commit.PackageVersionId, - - - CommitTimeStamp = commit.CommitTimeStamp, - RefType = commit.Action == PackageAction.PublishPackage ? - "nuget:PackageDetails" : "nuget:PackageDelete" - }; + var v = pkg.Versions.OrderByDescending(vc => vc.CommitNId).First(); - page.Items.Add(packageref); + var pkgref = new PackageRef + { + Version = v.FullString, + LastCommit = v.LatestCommit, + CommitId = v.LatestCommit.CommitId, + CommitTimeStamp = v.LatestCommit.CommitTimeStamp, + RefId = page.Id, + Id = v.PackageId + }; + page.Items.Add(pkgref); + } last = commit; i++; } - if (last!=null) + if (last != null) { CurrentCatalogIndex.CommitId = last.CommitId; } - throw new NotImplementedException(); + else + { + CurrentCatalogIndex.CommitId = "none"; + } } protected static bool CamelCaseMatch(string id, string query) diff --git a/src/isnd/Startup.cs b/src/isnd/Startup.cs index fa9b3fe..a1d158f 100644 --- a/src/isnd/Startup.cs +++ b/src/isnd/Startup.cs @@ -14,13 +14,8 @@ using isnd.Authorization; using isnd.Data.Roles; using Microsoft.AspNetCore.Authorization; using Unleash; -using System.Collections.Generic; -using System; -using Unleash.ClientFactory; -using isnd.Entities; using Microsoft.Extensions.Options; using isnd.Helpers; -using isnd.Services; namespace isnd { diff --git a/test/isn.tests/isn.tests.csproj b/test/isn.tests/isn.tests.csproj index 03f81f5..3ac8d60 100644 --- a/test/isn.tests/isn.tests.csproj +++ b/test/isn.tests/isn.tests.csproj @@ -1,7 +1,7 @@ - net472 + netcoreapp2.1 false @@ -10,7 +10,6 @@ - diff --git a/test/isnd.tests/isnd.tests.csproj b/test/isnd.tests/isnd.tests.csproj index e61f62c..62b23cc 100644 --- a/test/isnd.tests/isnd.tests.csproj +++ b/test/isnd.tests/isnd.tests.csproj @@ -9,10 +9,12 @@ - + - - + + + +