From 015a7396adb7b4d01e23e8457631c0260ce309a9 Mon Sep 17 00:00:00 2001 From: CodeLiturgy Date: Sat, 10 Sep 2022 05:28:41 +0100 Subject: [PATCH] k --- BlueWest.Api.Gateway/BlueWest.Api.Gateway.csproj | 6 ++++++ BlueWest.Api/BlueWest.Api.csproj | 4 ++++ BlueWest.Api/Context/ExchangeInterface.cs | 4 ++++ BlueWest.Api/Context/Extensions/ModelBuilderExtensions.cs | 8 +++++--- BlueWest.Api/Controllers/CountryController.cs | 2 +- BlueWest.Api/Startup.cs | 4 ++-- BlueWest.Api/StartupExtensions.cs | 8 +++----- BlueWest.Api/Users/ApplicationUser.cs | 3 +++ BlueWest.Api/Users/ApplicationUserDbContext.cs | 8 +++++++- BlueWest.Api/appsettings.json | 2 +- BlueWest.Data.Capital/BlueWest.Data.Capital.csproj | 4 ++++ BlueWest.Data.Geography/BlueWest.Data.Geography.csproj | 4 ++++ BlueWest/BlueWest.csproj | 4 ++++ 13 files changed, 48 insertions(+), 13 deletions(-) diff --git a/BlueWest.Api.Gateway/BlueWest.Api.Gateway.csproj b/BlueWest.Api.Gateway/BlueWest.Api.Gateway.csproj index 62993b8..d75c291 100644 --- a/BlueWest.Api.Gateway/BlueWest.Api.Gateway.csproj +++ b/BlueWest.Api.Gateway/BlueWest.Api.Gateway.csproj @@ -12,4 +12,10 @@ + + + + + + diff --git a/BlueWest.Api/BlueWest.Api.csproj b/BlueWest.Api/BlueWest.Api.csproj index 3c34cf8..aff487f 100644 --- a/BlueWest.Api/BlueWest.Api.csproj +++ b/BlueWest.Api/BlueWest.Api.csproj @@ -48,6 +48,10 @@ + + + + diff --git a/BlueWest.Api/Context/ExchangeInterface.cs b/BlueWest.Api/Context/ExchangeInterface.cs index 79bbfbe..f87f6ed 100644 --- a/BlueWest.Api/Context/ExchangeInterface.cs +++ b/BlueWest.Api/Context/ExchangeInterface.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using BlueWest.Tools; +using BlueWest.WebApi.Context.Users; using BlueWest.WebApi.EF; namespace BlueWest.WebApi.Interfaces @@ -16,6 +17,7 @@ namespace BlueWest.WebApi.Interfaces /// public sealed class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable { + private readonly ApplicationUserDbContext _applicationUserDbContext; private readonly EventManager _eventManager; private readonly CountryDbContext _countryDbContext; private readonly FinanceDbContext _financeDbContext; @@ -32,11 +34,13 @@ namespace BlueWest.WebApi.Interfaces /// Event manager injection public ExchangeInterface( + ApplicationUserDbContext applicationUserDbContext, CountryDbContext countryDbContext, FinanceDbContext financeDbContext, UserDbContext userDbContext, EventManager eventManager) { + _applicationUserDbContext = applicationUserDbContext; _countryDbContext = countryDbContext; _financeDbContext = financeDbContext; _userDbContext = userDbContext; diff --git a/BlueWest.Api/Context/Extensions/ModelBuilderExtensions.cs b/BlueWest.Api/Context/Extensions/ModelBuilderExtensions.cs index 83ece0d..f2a2157 100644 --- a/BlueWest.Api/Context/Extensions/ModelBuilderExtensions.cs +++ b/BlueWest.Api/Context/Extensions/ModelBuilderExtensions.cs @@ -25,6 +25,7 @@ namespace BlueWest.WebApi.EF.Model .ConfigureDatabaseKeys() .CurrencyModel() .ConfigureUserModel(); + //.ConfigureIdentityModel(); } @@ -110,15 +111,16 @@ namespace BlueWest.WebApi.EF.Model private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder) { - - // FinanceOp => User modelBuilder .Entity(builder => builder .HasOne() .WithMany(ft => ft.FinanceTransactions) .HasForeignKey(x => x.UserId)); - + + modelBuilder.Entity(b => b.HasOne() + .WithMany(x => x.Users) + .HasForeignKey(x => x.ApplicationUserId)); return modelBuilder; } diff --git a/BlueWest.Api/Controllers/CountryController.cs b/BlueWest.Api/Controllers/CountryController.cs index 0133a96..187af15 100644 --- a/BlueWest.Api/Controllers/CountryController.cs +++ b/BlueWest.Api/Controllers/CountryController.cs @@ -51,7 +51,7 @@ namespace BlueWest.WebApi.Controllers int orderDir = 1) { - var (success, countries) = _dbContext.GetCountries(skip, take, orderDir); + var (success, countries) = _dbContext.GetCountries( skip, take, orderDir); if (!success) return new NotFoundResult(); return Ok(countries); diff --git a/BlueWest.Api/Startup.cs b/BlueWest.Api/Startup.cs index 6e52315..0c513cf 100644 --- a/BlueWest.Api/Startup.cs +++ b/BlueWest.Api/Startup.cs @@ -132,7 +132,7 @@ namespace BlueWest.WebApi throw new InvalidOperationException("config.json doesn't specify a valid database. Use mysql or sqlite."); } - services.AddAuthServerServices(MyAllowSpecificOrigins, _configuration, _environment); + services = services.AddAuthServerServices(MyAllowSpecificOrigins, _configuration, _environment); services.AddScoped(); @@ -160,7 +160,7 @@ namespace BlueWest.WebApi c.RoutePrefix = "swagger"; c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1"); }); - //app.UseStaticFiles(); + app.UseStaticFiles(); //app.UseHttpsRedirection(); diff --git a/BlueWest.Api/StartupExtensions.cs b/BlueWest.Api/StartupExtensions.cs index 590e84e..d882eaa 100644 --- a/BlueWest.Api/StartupExtensions.cs +++ b/BlueWest.Api/StartupExtensions.cs @@ -99,22 +99,20 @@ namespace BlueWest.WebApi .AddDbContextPool(options => options.UseSqlite(sqliteConString)) .AddDbContextPool(options => options.UseSqlite(sqliteConString)) .AddDbContextPool(options => options.UseSqlite(sqliteConString)) - .AddDbContextPool(options => options.UseSqlite(sqliteConString)); + .AddDbContextPool(options => options.UseSqlite(sqliteConString)) + .AddDbContextPool(options => options.UseSqlite(sqliteConString)); } public static IServiceCollection AddAuthServerServices(this IServiceCollection services, string origins, IConfiguration configuration , IWebHostEnvironment environment) { - var sqliteConString = "Data Source=BlueWest.Api.db"; - - services.AddDbContext(options => options.UseSqlite(sqliteConString)); services.AddScoped(); services.AddScoped(); services - .AddScoped() + .AddScoped< UserRepository>() .AddScoped() .AddScoped() .AddScoped(); diff --git a/BlueWest.Api/Users/ApplicationUser.cs b/BlueWest.Api/Users/ApplicationUser.cs index dfe9d1b..fb791bb 100644 --- a/BlueWest.Api/Users/ApplicationUser.cs +++ b/BlueWest.Api/Users/ApplicationUser.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using BlueWest.Data; using Microsoft.AspNetCore.Identity; namespace BlueWest.WebApi.Context.Users; @@ -18,6 +20,7 @@ public class ApplicationUser : IdentityUser [PersonalData] public new string Id { get; set; } + public List Users { get; set; } /// /// Gets or sets the user name for this user. /// diff --git a/BlueWest.Api/Users/ApplicationUserDbContext.cs b/BlueWest.Api/Users/ApplicationUserDbContext.cs index 54459e3..291f650 100644 --- a/BlueWest.Api/Users/ApplicationUserDbContext.cs +++ b/BlueWest.Api/Users/ApplicationUserDbContext.cs @@ -52,6 +52,8 @@ public class ApplicationUserDbContext : IdentityDbContext< { base.OnModelCreating(builder); + + builder.Entity().ToTable("UserRoles"); builder.Entity(b => { b.HasMany() @@ -61,7 +63,7 @@ public class ApplicationUserDbContext : IdentityDbContext< builder.Entity().ToTable("ApplicationUser") .HasKey(x => x.Id); - + builder.Entity(b => @@ -90,6 +92,10 @@ public class ApplicationUserDbContext : IdentityDbContext< b.ToTable("UserRoles"); }); + builder.Entity(b => b.HasOne() + .WithMany(x => x.Users) + .HasForeignKey(x => x.ApplicationUserId)); + builder.ConfigureCurrentDbModel(); } diff --git a/BlueWest.Api/appsettings.json b/BlueWest.Api/appsettings.json index 54ceb96..547b74d 100644 --- a/BlueWest.Api/appsettings.json +++ b/BlueWest.Api/appsettings.json @@ -11,6 +11,6 @@ "DockerMySQL": "server=db;user=blueuser;password=dXjw127124dJ;database=bluedb;" }, "AuthSettings": { - "SecretKey": "d123d123d123fff12" + "SecretKey": "iJWHDmHLpUA283sqsfhqGbMRdRj1PVkH" } } diff --git a/BlueWest.Data.Capital/BlueWest.Data.Capital.csproj b/BlueWest.Data.Capital/BlueWest.Data.Capital.csproj index 423d42d..1309c49 100644 --- a/BlueWest.Data.Capital/BlueWest.Data.Capital.csproj +++ b/BlueWest.Data.Capital/BlueWest.Data.Capital.csproj @@ -11,6 +11,10 @@ + + + + diff --git a/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj b/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj index f3f4eda..4c7b476 100644 --- a/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj +++ b/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/BlueWest/BlueWest.csproj b/BlueWest/BlueWest.csproj index 4860e23..79595ef 100644 --- a/BlueWest/BlueWest.csproj +++ b/BlueWest/BlueWest.csproj @@ -7,4 +7,8 @@ PerformanceSolution + + + +