catalog index

broken/ef
Paul Schneider 3 years ago
parent f6fa7a0ec9
commit d8bfdc293d
4 changed files with 36 additions and 34 deletions

@ -14,7 +14,7 @@ namespace isnd.Data.Catalog
[JsonProperty("count")] [JsonProperty("count")]
public int Count { get => Items.Count; } public int Count { get => Items?.Count ?? 0; }
public string CommitId { get; set; } public string CommitId { get; set; }
public DateTime CommitTimeStamp { get; set; } public DateTime CommitTimeStamp { get; set; }

@ -32,13 +32,13 @@ namespace isnd.Data
public virtual Package Package { get; set; } public virtual Package Package { get; set; }
[Required][JsonIgnore] [Required][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 string NugetLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nupkg"; public string NugetLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nupkg";

@ -23,9 +23,9 @@ namespace isnd.Services
IOptions<IsndSettings> siteConfigOptionsOptions) IOptions<IsndSettings> siteConfigOptionsOptions)
{ {
this.dbContext = dbContext; this.dbContext = dbContext;
isndSettings = siteConfigOptionsOptions.Value;
extApiUrl = isndSettings.ExternalUrl + "/package";
CurrentCatalogIndex = GetCatalogIndex(); CurrentCatalogIndex = GetCatalogIndex();
pmConfigOptions = siteConfigOptionsOptions.Value;
extApiUrl = pmConfigOptions.ExternalUrl + "/package";
} }
@ -138,7 +138,7 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get; protected set; } public static CatalogIndex CurrentCatalogIndex { get; protected set; }
public static List<Page> CurrentCatalogPages { get; protected set; } public static List<Page> CurrentCatalogPages { get; protected set; }
private IsndSettings pmConfigOptions; private IsndSettings isndSettings;
private string extApiUrl; private string extApiUrl;
public virtual CatalogIndex GetCatalogIndex() public virtual CatalogIndex GetCatalogIndex()
@ -157,7 +157,7 @@ namespace isnd.Services
var oldPages = CurrentCatalogPages; var oldPages = CurrentCatalogPages;
CurrentCatalogIndex = new CatalogIndex CurrentCatalogIndex = new CatalogIndex
{ {
Id = extApiUrl
}; };
CurrentCatalogPages = new List<Page>(); CurrentCatalogPages = new List<Page>();
@ -165,17 +165,17 @@ namespace isnd.Services
Commit last = null; Commit last = null;
PageRef pageRef = null; PageRef pageRef = null;
Page page = null; Page page = null;
i = pmConfigOptions.CatalogPageLen; i = isndSettings.CatalogPageLen;
foreach (var commit in scope) foreach (var commit in scope)
{ {
if (i >= this.pmConfigOptions.CatalogPageLen) if (i >= this.isndSettings.CatalogPageLen)
{ {
page = new Page page = new Page
{ {
Parent = pmConfigOptions.ExternalUrl + "/package", Parent = isndSettings.ExternalUrl + "/package",
CommitId = commit.CommitId, CommitId = commit.CommitId,
CommitTimeStamp = commit.CommitTimeStamp, CommitTimeStamp = commit.CommitTimeStamp,
Id = this.pmConfigOptions.ExternalUrl + "/package/index-" + p++ Id = this.isndSettings.ExternalUrl + "/package/index-" + p++
}; };
CurrentCatalogPages.Add(page); CurrentCatalogPages.Add(page);

@ -32,12 +32,20 @@ namespace isnd
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddDbContext<ApplicationDbContext>(options => var smtpSettingsconf = Configuration.GetSection("Smtp");
options.UseNpgsql( var isndSettingsconf = Configuration.GetSection("Isn");
Configuration.GetConnectionString("DefaultConnection"))); var adminStartupListConf = Configuration.GetSection("AdminList");
var unleashConf = Configuration.GetSection("Unleash");
services.AddIdentity<ApplicationUser, IdentityRole>() services.Configure<SmtpSettings>(smtpSettingsconf)
.Configure<IsndSettings>(isndSettingsconf)
.Configure<AdminStartupList>(adminStartupListConf)
.Configure<UnleashClientSettings>(unleashConf)
.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate")
.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
Configuration.GetConnectionString("DefaultConnection")))
.AddIdentity<ApplicationUser, IdentityRole>()
.AddRoles<IdentityRole>() .AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>() .AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager() .AddSignInManager()
@ -45,12 +53,9 @@ namespace isnd
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
services.AddMvc(); services.AddMvc();
services.AddDataProtection(); services.AddDataProtection();
services.AddTransient<IMailer, EmailSender>();
services.AddTransient<IEmailSender, EmailSender>();
services.AddAuthorization(options => services.AddAuthorization(options =>
{ {
options.AddPolicy(Constants.RequireAdminPolicyName, options.AddPolicy(Constants.RequireAdminPolicyName,
@ -58,26 +63,23 @@ namespace isnd
options.AddPolicy(Constants.RequireValidApiKey, policy => options.AddPolicy(Constants.RequireValidApiKey, policy =>
policy.Requirements.Add(new ValidApiKeyRequirement())); policy.Requirements.Add(new ValidApiKeyRequirement()));
}); })
.AddTransient<IMailer, EmailSender>()
services.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>(); .AddTransient<IEmailSender, EmailSender>()
services.AddSingleton<IUnleash>(s => .AddTransient<IPackageManager, PackageManager>()
.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>()
.AddSingleton(s =>
{ {
var config = s.GetRequiredService<IOptions<UnleashClientSettings>>(); var config = s.GetRequiredService<IOptions<UnleashClientSettings>>();
if (config.Value==null)
throw new System.Exception("No unleash client settings");
if (config.Value.ApiUrl==null)
throw new System.Exception("No unleash client ApiUrl");
if (config.Value.ClientApiKey==null)
throw new System.Exception("No unleash client ClientApiKey");
return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value); return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value);
}); });
services.AddTransient<IPackageManager, PackageManager>();
// _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf);
var isndSettingsconf = Configuration.GetSection("Isn");
services.Configure<IsndSettings>(isndSettingsconf);
var adminStartupListConf = Configuration.GetSection("AdminList");
services.Configure<AdminStartupList>(adminStartupListConf);
var unleashConf = Configuration.GetSection("Unleash");
services.Configure<UnleashClientSettings>(unleashConf);
services.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate");
} }

Loading…