Commit Id and TimerStamps
This commit is contained in:
@ -19,10 +19,6 @@ using isnd.Entities;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using isn.abst;
|
using isn.abst;
|
||||||
using isnd.Data.Packages;
|
using isnd.Data.Packages;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
||||||
using isn;
|
|
||||||
using isnd.Helpers;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace isnd.Controllers
|
namespace isnd.Controllers
|
||||||
@ -55,8 +51,6 @@ namespace isnd.Controllers
|
|||||||
TimeStamp = DateTimeOffset.Now.ToUniversalTime()
|
TimeStamp = DateTimeOffset.Now.ToUniversalTime()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (IFormFile file in Request.Form.Files)
|
foreach (IFormFile file in Request.Form.Files)
|
||||||
{
|
{
|
||||||
string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ??
|
string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ??
|
||||||
@ -122,27 +116,23 @@ namespace isnd.Controllers
|
|||||||
var destdir = new DirectoryInfo(dest.DirectoryName);
|
var destdir = new DirectoryInfo(dest.DirectoryName);
|
||||||
if (dest.Exists)
|
if (dest.Exists)
|
||||||
{
|
{
|
||||||
logger.LogWarning($"Existant package in disk : {dest.FullName}");
|
logger.LogWarning($"Existant package on disk : '{dest.FullName}'");
|
||||||
// La version existe sur le disque,
|
// La version existe sur le disque,
|
||||||
// mais si elle ne l'est pas en base de donnéés,
|
// mais si elle ne l'est pas en base de donnéés,
|
||||||
// on remplace la version sur disque.
|
// on remplace la version sur disque.
|
||||||
string exFullString = version.ToFullString();
|
string exFullString = version.ToFullString();
|
||||||
var pkgv = dbContext.PackageVersions.
|
var pkgv = dbContext.PackageVersions.
|
||||||
Include(v=>v.LatestCommit)
|
Include(v=>v.LatestCommit)
|
||||||
.Single(
|
.SingleOrDefault(
|
||||||
v => v.PackageId == pkg.Id && v.FullString == exFullString
|
v => v.PackageId == pkg.Id && v.FullString == exFullString
|
||||||
);
|
);
|
||||||
if (pkgv!=null && pkgv.IsDeleted)
|
if (pkgv!=null && ! pkgv.IsDeleted)
|
||||||
{
|
|
||||||
dest.Delete();
|
|
||||||
}
|
|
||||||
else if (pkgv != null)
|
|
||||||
{
|
{
|
||||||
string msg = $"existant : {pkg.Id}-{exFullString}";
|
string msg = $"existant : {pkg.Id}-{exFullString}";
|
||||||
logger.LogWarning("400 : {msg}", msg);
|
logger.LogWarning("400 : {msg}", msg);
|
||||||
ModelState.AddModelError("pkgversion", msg);
|
ModelState.AddModelError("pkgversion", msg);
|
||||||
return BadRequest(this.CreateAPIKO("existant"));
|
return BadRequest(this.CreateAPIKO("existant"));
|
||||||
}
|
} else dest.Delete();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
if (!destdir.Exists) destdir.Create();
|
if (!destdir.Exists) destdir.Create();
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using isnd.Data;
|
|
||||||
using isnd.Data.ApiKeys;
|
using isnd.Data.ApiKeys;
|
||||||
using isnd.Data.Packages;
|
using isnd.Data.Packages;
|
||||||
|
|
||||||
@ -22,6 +17,17 @@ namespace isnd.Data
|
|||||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
: base(options) { }
|
: base(options) { }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(builder);
|
||||||
|
_ = builder.Entity<PackageVersion>()
|
||||||
|
.HasKey( v => new { v.PackageId, v.FullString } );
|
||||||
|
_ = builder.Entity<PackageVersion>()
|
||||||
|
.HasOne(v => v.Package).WithMany(p => p.Versions).HasForeignKey(x => x.PackageId);
|
||||||
|
// _ = builder.Entity<Package>().HasMany(p => p.Versions).WithOne(V => V.Package).HasForeignKey(x => new { x.PackageId, x.FullString });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// User API keys
|
/// User API keys
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,7 +39,7 @@ namespace isnd.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public DbSet<Package> Packages { get; set; }
|
public DbSet<Package> Packages { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Package Versions
|
/// Package Versions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -22,6 +22,9 @@ namespace isnd.Data.Catalog
|
|||||||
Version = pkg.FullString;
|
Version = pkg.FullString;
|
||||||
authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>";
|
authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>";
|
||||||
packageContent = apiBase + pkg.NugetLink;
|
packageContent = apiBase + pkg.NugetLink;
|
||||||
|
CommitId = pkg.CommitId;
|
||||||
|
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("@type")]
|
[JsonProperty("@type")]
|
||||||
|
@ -20,11 +20,8 @@ namespace isnd.Data.Catalog
|
|||||||
{
|
{
|
||||||
new CatalogPage(bid, pkg.Id, apiBase, pkg.Versions)
|
new CatalogPage(bid, pkg.Id, apiBase, pkg.Versions)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CommitId = pkg.LatestCommit.CommitId;
|
CommitId = pkg.LatestCommit.CommitId;
|
||||||
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("count")]
|
[JsonProperty("count")]
|
||||||
|
@ -2,9 +2,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
|
||||||
using isnd.Data.Catalog;
|
|
||||||
using isnd.Data.Packages.Catalog;
|
|
||||||
using isnd.Interfaces;
|
using isnd.Interfaces;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -24,7 +21,7 @@ namespace isnd.Data.Packages
|
|||||||
DateTimeOffset CommitTimeStamp { get; set; }
|
DateTimeOffset CommitTimeStamp { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Package : IObject, IPackage
|
public class Package
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Required]
|
[Required]
|
||||||
@ -53,16 +50,16 @@ namespace isnd.Data.Packages
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
[Required]
|
[Required]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[ForeignKey("LatestCommit")]
|
||||||
public long CommitNId { get; set; }
|
public long CommitNId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public string CommitId { get => CommitNId.ToString(); }
|
public string CommitId { get => CommitNId.ToString(); }
|
||||||
|
|
||||||
[ForeignKey("CommitNId")]
|
|
||||||
|
|
||||||
public virtual Commit LatestCommit { get; set; }
|
public virtual Commit LatestCommit { get; set; }
|
||||||
public DateTimeOffset CommitTimeStamp { get; set; }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Security.Principal;
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
@ -13,7 +14,7 @@ using NuGet.Versioning;
|
|||||||
namespace isnd.Data
|
namespace isnd.Data
|
||||||
{
|
{
|
||||||
[PrimaryKey("PackageId", "FullString")]
|
[PrimaryKey("PackageId", "FullString")]
|
||||||
public class PackageVersion
|
public class PackageVersion
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[ForeignKey("Package")]
|
[ForeignKey("Package")]
|
||||||
|
@ -12,7 +12,7 @@ using isnd.Data;
|
|||||||
namespace isnd.Migrations
|
namespace isnd.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
[Migration("20230430192411_pkgversions")]
|
[Migration("20230430215312_pkgversions")]
|
||||||
partial class pkgversions
|
partial class pkgversions
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -317,9 +317,6 @@ namespace isnd.Migrations
|
|||||||
b.Property<long>("CommitNId")
|
b.Property<long>("CommitNId")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("CommitTimeStamp")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.HasMaxLength(1024)
|
.HasMaxLength(1024)
|
||||||
.HasColumnType("character varying(1024)");
|
.HasColumnType("character varying(1024)");
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ namespace isnd.Migrations
|
|||||||
name: "IX_PackageVersions_PackageId",
|
name: "IX_PackageVersions_PackageId",
|
||||||
table: "PackageVersions");
|
table: "PackageVersions");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CommitTimeStamp",
|
||||||
|
table: "Packages");
|
||||||
|
|
||||||
migrationBuilder.AddPrimaryKey(
|
migrationBuilder.AddPrimaryKey(
|
||||||
name: "PK_PackageVersions",
|
name: "PK_PackageVersions",
|
||||||
table: "PackageVersions",
|
table: "PackageVersions",
|
||||||
@ -31,6 +36,13 @@ namespace isnd.Migrations
|
|||||||
name: "PK_PackageVersions",
|
name: "PK_PackageVersions",
|
||||||
table: "PackageVersions");
|
table: "PackageVersions");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "CommitTimeStamp",
|
||||||
|
table: "Packages",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
||||||
|
|
||||||
migrationBuilder.AddPrimaryKey(
|
migrationBuilder.AddPrimaryKey(
|
||||||
name: "PK_PackageVersions",
|
name: "PK_PackageVersions",
|
||||||
table: "PackageVersions",
|
table: "PackageVersions",
|
@ -314,9 +314,6 @@ namespace isnd.Migrations
|
|||||||
b.Property<long>("CommitNId")
|
b.Property<long>("CommitNId")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("CommitTimeStamp")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.HasMaxLength(1024)
|
.HasMaxLength(1024)
|
||||||
.HasColumnType("character varying(1024)");
|
.HasColumnType("character varying(1024)");
|
||||||
|
@ -281,6 +281,8 @@ namespace isnd.Services
|
|||||||
.SingleAsync(p => p.Id.ToLower() == query.Query);
|
.SingleAsync(p => p.Id.ToLower() == query.Query);
|
||||||
if (scope.Versions.Count==0) return null;
|
if (scope.Versions.Count==0) return null;
|
||||||
string bid = $"{apiBase}{ApiConfig.Registration}";
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
||||||
|
foreach (var version in scope.Versions)
|
||||||
|
version.LatestCommit = dbContext.Commits.Single(c=>c.Id == version.CommitNId);
|
||||||
return
|
return
|
||||||
new PackageRegistration(bid, apiBase, scope);
|
new PackageRegistration(bid, apiBase, scope);
|
||||||
}
|
}
|
||||||
@ -299,6 +301,11 @@ namespace isnd.Services
|
|||||||
.ToListAsync()
|
.ToListAsync()
|
||||||
);
|
);
|
||||||
var pkgs = scope;
|
var pkgs = scope;
|
||||||
|
foreach (var pkg in pkgs)
|
||||||
|
{
|
||||||
|
foreach (var version in pkg.Versions)
|
||||||
|
version.LatestCommit = dbContext.Commits.Single(c=>c.Id == version.CommitNId);
|
||||||
|
}
|
||||||
return pkgs.Select(p => new PackageRegistration(bid, apiBase, p));
|
return pkgs.Select(p => new PackageRegistration(bid, apiBase, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user