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