This commit is contained in:
CodeLiturgy 2022-09-10 05:28:41 +01:00
parent 5c32055f6a
commit 015a7396ad
13 changed files with 48 additions and 13 deletions

View File

@ -12,4 +12,10 @@
<ProjectReference Include="..\BlueWest\BlueWest.csproj" /> <ProjectReference Include="..\BlueWest\BlueWest.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="obj\Debug\net6.0\apphost.exe" />
<Content Include="obj\Debug\net6.0\BlueWest.Api.Gateway.csproj.FileListAbsolute.txt" />
<Content Include="obj\rider.project.restore.info" />
</ItemGroup>
</Project> </Project>

View File

@ -49,6 +49,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="obj\rider.project.restore.info" />
</ItemGroup>
<Import Project="..\include\BlueWest.EfMethods\src\BlueWest.EfMethods\BlueWest.EfMethods.props" /> <Import Project="..\include\BlueWest.EfMethods\src\BlueWest.EfMethods\BlueWest.EfMethods.props" />

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using BlueWest.Tools; using BlueWest.Tools;
using BlueWest.WebApi.Context.Users;
using BlueWest.WebApi.EF; using BlueWest.WebApi.EF;
namespace BlueWest.WebApi.Interfaces namespace BlueWest.WebApi.Interfaces
@ -16,6 +17,7 @@ namespace BlueWest.WebApi.Interfaces
/// ///
public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
{ {
private readonly ApplicationUserDbContext _applicationUserDbContext;
private readonly EventManager _eventManager; private readonly EventManager _eventManager;
private readonly CountryDbContext _countryDbContext; private readonly CountryDbContext _countryDbContext;
private readonly FinanceDbContext _financeDbContext; private readonly FinanceDbContext _financeDbContext;
@ -32,11 +34,13 @@ namespace BlueWest.WebApi.Interfaces
/// <param name="eventManager">Event manager injection</param> /// <param name="eventManager">Event manager injection</param>
public ExchangeInterface( public ExchangeInterface(
ApplicationUserDbContext applicationUserDbContext,
CountryDbContext countryDbContext, CountryDbContext countryDbContext,
FinanceDbContext financeDbContext, FinanceDbContext financeDbContext,
UserDbContext userDbContext, UserDbContext userDbContext,
EventManager eventManager) EventManager eventManager)
{ {
_applicationUserDbContext = applicationUserDbContext;
_countryDbContext = countryDbContext; _countryDbContext = countryDbContext;
_financeDbContext = financeDbContext; _financeDbContext = financeDbContext;
_userDbContext = userDbContext; _userDbContext = userDbContext;

View File

@ -25,6 +25,7 @@ namespace BlueWest.WebApi.EF.Model
.ConfigureDatabaseKeys() .ConfigureDatabaseKeys()
.CurrencyModel() .CurrencyModel()
.ConfigureUserModel(); .ConfigureUserModel();
//.ConfigureIdentityModel(); //.ConfigureIdentityModel();
} }
@ -110,8 +111,6 @@ namespace BlueWest.WebApi.EF.Model
private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder) private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder)
{ {
// FinanceOp => User // FinanceOp => User
modelBuilder modelBuilder
.Entity<FinanceOp>(builder => builder .Entity<FinanceOp>(builder => builder
@ -119,6 +118,9 @@ namespace BlueWest.WebApi.EF.Model
.WithMany(ft => ft.FinanceTransactions) .WithMany(ft => ft.FinanceTransactions)
.HasForeignKey(x => x.UserId)); .HasForeignKey(x => x.UserId));
modelBuilder.Entity<User>(b => b.HasOne<ApplicationUser>()
.WithMany(x => x.Users)
.HasForeignKey(x => x.ApplicationUserId));
return modelBuilder; return modelBuilder;
} }

View File

@ -132,7 +132,7 @@ namespace BlueWest.WebApi
throw new InvalidOperationException("config.json doesn't specify a valid database. Use mysql or sqlite."); 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<ExchangeInterface>(); services.AddScoped<ExchangeInterface>();
@ -160,7 +160,7 @@ namespace BlueWest.WebApi
c.RoutePrefix = "swagger"; c.RoutePrefix = "swagger";
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1"); c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1");
}); });
//app.UseStaticFiles(); app.UseStaticFiles();
//app.UseHttpsRedirection(); //app.UseHttpsRedirection();

View File

@ -99,15 +99,13 @@ namespace BlueWest.WebApi
.AddDbContextPool<UserDbContext>(options => options.UseSqlite(sqliteConString)) .AddDbContextPool<UserDbContext>(options => options.UseSqlite(sqliteConString))
.AddDbContextPool<CountryDbContext>(options => options.UseSqlite(sqliteConString)) .AddDbContextPool<CountryDbContext>(options => options.UseSqlite(sqliteConString))
.AddDbContextPool<FinanceDbContext>(options => options.UseSqlite(sqliteConString)) .AddDbContextPool<FinanceDbContext>(options => options.UseSqlite(sqliteConString))
.AddDbContextPool<CompanyDbContext>(options => options.UseSqlite(sqliteConString)); .AddDbContextPool<CompanyDbContext>(options => options.UseSqlite(sqliteConString))
.AddDbContextPool<ApplicationUserDbContext>(options => options.UseSqlite(sqliteConString));
} }
public static IServiceCollection AddAuthServerServices(this IServiceCollection services, string origins, IConfiguration configuration , IWebHostEnvironment environment) public static IServiceCollection AddAuthServerServices(this IServiceCollection services, string origins, IConfiguration configuration , IWebHostEnvironment environment)
{ {
var sqliteConString = "Data Source=BlueWest.Api.db";
services.AddDbContext<ApplicationUserDbContext>(options => options.UseSqlite(sqliteConString));
services.AddScoped<IJwtTokenHandler, JwtTokenHandler>(); services.AddScoped<IJwtTokenHandler, JwtTokenHandler>();
services.AddScoped<IJwtFactory, JwtFactory>(); services.AddScoped<IJwtFactory, JwtFactory>();

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using BlueWest.Data;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
namespace BlueWest.WebApi.Context.Users; namespace BlueWest.WebApi.Context.Users;
@ -18,6 +20,7 @@ public class ApplicationUser : IdentityUser<string>
[PersonalData] [PersonalData]
public new string Id { get; set; } public new string Id { get; set; }
public List<User> Users { get; set; }
/// <summary> /// <summary>
/// Gets or sets the user name for this user. /// Gets or sets the user name for this user.
/// </summary> /// </summary>

View File

@ -52,6 +52,8 @@ public class ApplicationUserDbContext : IdentityDbContext<
{ {
base.OnModelCreating(builder); base.OnModelCreating(builder);
builder.Entity<ApplicationUserRole>().ToTable("UserRoles");
builder.Entity<ApplicationUser>(b => builder.Entity<ApplicationUser>(b =>
{ {
b.HasMany<ApplicationUserRole>() b.HasMany<ApplicationUserRole>()
@ -90,6 +92,10 @@ public class ApplicationUserDbContext : IdentityDbContext<
b.ToTable("UserRoles"); b.ToTable("UserRoles");
}); });
builder.Entity<User>(b => b.HasOne<ApplicationUser>()
.WithMany(x => x.Users)
.HasForeignKey(x => x.ApplicationUserId));
builder.ConfigureCurrentDbModel(); builder.ConfigureCurrentDbModel();
} }

View File

@ -11,6 +11,6 @@
"DockerMySQL": "server=db;user=blueuser;password=dXjw127124dJ;database=bluedb;" "DockerMySQL": "server=db;user=blueuser;password=dXjw127124dJ;database=bluedb;"
}, },
"AuthSettings": { "AuthSettings": {
"SecretKey": "d123d123d123fff12" "SecretKey": "iJWHDmHLpUA283sqsfhqGbMRdRj1PVkH"
} }
} }

View File

@ -11,6 +11,10 @@
<ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" /> <ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="obj\rider.project.restore.info" />
</ItemGroup>
<Import Project="..\include\BlueWest.MapTo\src\BlueWest.MapTo\MapTo.props" /> <Import Project="..\include\BlueWest.MapTo\src\BlueWest.MapTo\MapTo.props" />
</Project> </Project>

View File

@ -11,4 +11,8 @@
<ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" /> <ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="obj\rider.project.restore.info" />
</ItemGroup>
</Project> </Project>

View File

@ -7,4 +7,8 @@
<RootNamespace>PerformanceSolution</RootNamespace> <RootNamespace>PerformanceSolution</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="obj\rider.project.restore.info" />
</ItemGroup>
</Project> </Project>