Improvements efcore relation mappings, UserModels, etc...
This commit is contained in:
parent
733fdd2484
commit
0b0aa70e5c
|
|
@ -15,7 +15,7 @@
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
<PackageReference Include="Moq" Version="4.20.69" />
|
<PackageReference Include="Moq" Version="4.20.70" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ namespace TIAM.Database.Test
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||||
|
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
|
||||||
|
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
|
||||||
public async Task SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
|
public async Task SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
|
||||||
{
|
{
|
||||||
var userId = Guid.Parse(userIdString);
|
var userId = Guid.Parse(userIdString);
|
||||||
|
|
@ -73,6 +75,8 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsNotNull(userModel.UserDto);
|
Assert.IsNotNull(userModel.UserDto);
|
||||||
Assert.IsNotNull(userModel.Profile);
|
Assert.IsNotNull(userModel.Profile);
|
||||||
|
|
||||||
|
if (userId != Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00")) return; //csak az "540271F6.."-nek van product-ja! - J.
|
||||||
|
|
||||||
Assert.IsTrue(userModel.Products.Count > 0);
|
Assert.IsTrue(userModel.Products.Count > 0);
|
||||||
Assert.IsTrue(userModel.UserProductMappings.Count > 0);
|
Assert.IsTrue(userModel.UserProductMappings.Count > 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
||||||
new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
||||||
|
|
||||||
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
|
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,9 @@ namespace TIAM.Database.DbContexts.Users
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
||||||
|
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
|
||||||
|
|
||||||
modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
|
//modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
|
||||||
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ public static class UserDbSetExtensions
|
||||||
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email);
|
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email);
|
||||||
|
|
||||||
public static UserModelDto? GetUserModelDtoById(this IUserDbSet ctx, Guid userId)
|
public static UserModelDto? GetUserModelDtoById(this IUserDbSet ctx, Guid userId)
|
||||||
=> ctx.GetUsersById(userId).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault();
|
=> ctx.GetUsersById(userId).Select(user => new UserModelDto(user)).FirstOrDefault();
|
||||||
|
|
||||||
public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email)
|
public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email)
|
||||||
=> ctx.GetUsersByEmail(email).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault();
|
=> ctx.GetUsersByEmail(email).Select(user => new UserModelDto(user)).FirstOrDefault();
|
||||||
|
|
||||||
public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx)
|
public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx)
|
||||||
=> ctx.Users.Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products));
|
=> ctx.Users.Select(user => new UserModelDto(user));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +31,11 @@ public static class UserEntityTypeBuilderExtensions
|
||||||
modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude);
|
modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void BuildUserProfileRelation<TUser, TProfile>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
|
||||||
|
{
|
||||||
|
modelBuilder.Navigation(e => e.Profile).AutoInclude(true);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion User
|
#endregion User
|
||||||
|
|
||||||
#region UserProductMapping
|
#region UserProductMapping
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ public class UserEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<Use
|
||||||
{
|
{
|
||||||
//base.Configure(builder);
|
//base.Configure(builder);
|
||||||
|
|
||||||
|
builder.BuildUserProfileRelation<User, Profile>();
|
||||||
builder.BuildUserToUserProductMappingRelation();
|
builder.BuildUserToUserProductMappingRelation();
|
||||||
builder.BuildUserToServiceProviderRelation<User, Profile>();
|
builder.BuildUserToServiceProviderRelation<User, Profile>();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto>
|
||||||
public List<Product> Products = new();
|
public List<Product> Products = new();
|
||||||
|
|
||||||
public UserModelDto(){}
|
public UserModelDto(){}
|
||||||
public UserModelDto(User user, Profile profile, List<UserProductMapping> userProductMappings, List<Product> products) : base(user, profile)
|
public UserModelDto(User user) : base(user)
|
||||||
{
|
{
|
||||||
foreach (var product in products)
|
foreach (var product in user.Products)
|
||||||
{
|
{
|
||||||
Products.Add(new Product(product.Id, product.ServiceProviderId, product.ProductType, product.Name, product.Description, product.Price, product.JsonDetails));
|
Products.Add(new Product(product.Id, product.ServiceProviderId, product.ProductType, product.Name, product.Description, product.Price, product.JsonDetails));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var userProduct in userProductMappings)
|
foreach (var userProduct in user.UserProductMappings)
|
||||||
{
|
{
|
||||||
UserProductMappings.Add(new UserProductMapping(userProduct.Id, userProduct.UserId, userProduct.ProductId));
|
UserProductMappings.Add(new UserProductMapping(userProduct.Id, userProduct.UserId, userProduct.ProductId));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ else
|
||||||
@foreach (var dest in Users)
|
@foreach (var dest in Users)
|
||||||
{
|
{
|
||||||
<p>
|
<p>
|
||||||
@(dest.Profile == null ? dest.UserDto.Id.ToString() : dest.Profile.Name)
|
@(dest.Profile.Name.IsNullOrWhiteSpace() ? dest.Id.ToString() : dest.Profile.Name)
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ namespace TIAMWebApp.Client.Services
|
||||||
|
|
||||||
public async Task<UserSessionModel> IsLoggedInAsync(Guid id)
|
public async Task<UserSessionModel> IsLoggedInAsync(Guid id)
|
||||||
{
|
{
|
||||||
UserSessionModel user = null;
|
|
||||||
//api call to get user
|
//api call to get user
|
||||||
var userModelDto = await GetUserByIdAsync(id);
|
var userModelDto = await GetUserByIdAsync(id);
|
||||||
|
|
||||||
|
|
@ -56,7 +55,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
logToBrowserConsole.LogToBC($"{hasProperties.Count} properties found");
|
logToBrowserConsole.LogToBC($"{hasProperties.Count} properties found");
|
||||||
|
|
||||||
//create user session model
|
//create user session model
|
||||||
user = new UserSessionModel(userModelDto.Id, UserType.User, userModelDto.Profile?.Name, hasProperties, 1);
|
var user = new UserSessionModel(userModelDto.Id, UserType.User, userModelDto.Profile?.Name, hasProperties, 1);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="GoogleApi" Version="5.2.4" />
|
<PackageReference Include="GoogleApi" Version="5.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue