From 00a95287329a0cc446d2ea40caa7a4c022ff7dd9 Mon Sep 17 00:00:00 2001 From: "jozsef.b@aycode.com" <9Rj@D}fVwBaN> Date: Fri, 22 Dec 2023 06:13:43 +0100 Subject: [PATCH] Impelement ServicProvider and Mapping to AcUserModel; refactoring, improvements, fixes, etc... --- TIAM.Database.Test/UserDalTests.cs | 38 ++++++++++++++----- TIAM.Database/DataLayers/Users/UserDal.cs | 2 +- .../DbContexts/Users/IUserDbContext.cs | 2 +- TIAM.Database/DbSets/Users/IUserDbSet.cs | 2 +- .../Users/UserEntityTypeConfigurations.cs | 2 +- .../ServiceProviders/ServiceProvider.cs | 3 +- TIAM.Entities/Users/IUser.cs | 2 +- TIAM.Entities/Users/IUserDto.cs | 2 +- TIAM.Entities/Users/User.cs | 2 +- TIAM.Entities/Users/UserProductMapping.cs | 2 - TIAM.Entities/Users/UserToServiceProvider.cs | 9 +++++ TIAM.Models/Dtos/Users/UserDto.cs | 1 + TIAM.Models/Dtos/Users/UserModelDto.cs | 15 ++++++-- .../TIAMWebApp.Shared.Application.csproj | 1 - 14 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 TIAM.Entities/Users/UserToServiceProvider.cs diff --git a/TIAM.Database.Test/UserDalTests.cs b/TIAM.Database.Test/UserDalTests.cs index 8aaea0db..f1b3f69c 100644 --- a/TIAM.Database.Test/UserDalTests.cs +++ b/TIAM.Database.Test/UserDalTests.cs @@ -19,7 +19,7 @@ using TIAM.Entities.ServiceProviders; namespace TIAM.Database.Test { [TestClass] - public class UserDalTests : AcUserDalTestBase + public class UserDalTests : AcUserDalTestBase { private Mock _mockContext; @@ -40,18 +40,33 @@ namespace TIAM.Database.Test [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] - public override void GetUserById_ReturnsUser_WhenUserExists(string userIdString) - => base.GetUserById_ReturnsUser_WhenUserExists(userIdString); + public void GetUserById_ReturnsUser_WhenUserAndRelationsExists(string userIdString) + { + var user = AcBase_GetUserById_ReturnsUser_WhenUserExists(userIdString); + + Assert.IsTrue(user.ServiceProviders.Count > 0); + Assert.IsTrue(user.UserToServiceProviders.Count > 0); + } + + [TestMethod] + [DataRow("test@tiam.hu")] + public void GetUserByEmail_ReturnsUser_WhenUserAndRelationsExists(string email) + { + var user = AcBase_GetUserByEmail_ReturnsUser_WhenUserExists(email); + + Assert.IsTrue(user.ServiceProviders.Count > 0); + Assert.IsTrue(user.UserToServiceProviders.Count > 0); + } [TestMethod] [DataRow("test@tiam.hu")] - public override void GetUserByEmail_ReturnsUser_WhenUserExists(string email) - => base.GetUserByEmail_ReturnsUser_WhenUserExists(email); - - [TestMethod] - [DataRow("test@tiam.hu")] - public override Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email) - => base.GetUserByEmailAsync_ReturnsUser_WhenUserExists(email); + public async Task GetUserByEmailAsync_ReturnsUser_WhenUserAndRelationsExists(string email) + { + var user = await AcBase_GetUserByEmailAsync_ReturnsUser_WhenUserExists(email); + + Assert.IsTrue(user.ServiceProviders.Count > 0); + Assert.IsTrue(user.UserToServiceProviders.Count > 0); + } [TestMethod] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] @@ -80,6 +95,9 @@ namespace TIAM.Database.Test Assert.IsTrue(userModel.Products.Count > 0); Assert.IsTrue(userModel.UserProductMappings.Count > 0); + + Assert.IsTrue(userModel.ServiceProviders.Count > 0); + Assert.IsTrue(userModel.UserToServiceProviders.Count > 0); } //[TestMethod] diff --git a/TIAM.Database/DataLayers/Users/UserDal.cs b/TIAM.Database/DataLayers/Users/UserDal.cs index d64743a3..642d8a25 100644 --- a/TIAM.Database/DataLayers/Users/UserDal.cs +++ b/TIAM.Database/DataLayers/Users/UserDal.cs @@ -17,7 +17,7 @@ using TIAM.Models.Dtos.Users; namespace TIAM.Database.DataLayers.Users { - public class UserDal : AcUserDalBase + public class UserDal : AcUserDalBase { public UserDal() : base() diff --git a/TIAM.Database/DbContexts/Users/IUserDbContext.cs b/TIAM.Database/DbContexts/Users/IUserDbContext.cs index 9a9db621..311b4d7e 100644 --- a/TIAM.Database/DbContexts/Users/IUserDbContext.cs +++ b/TIAM.Database/DbContexts/Users/IUserDbContext.cs @@ -7,6 +7,6 @@ using TIAM.Entities.Users; namespace TIAM.Database.DbContexts.Users; -public interface IUserDbContext : IAcUserDbContextBase, IUserDbSet +public interface IUserDbContext : IAcUserDbContextBase, IUserDbSet { } \ No newline at end of file diff --git a/TIAM.Database/DbSets/Users/IUserDbSet.cs b/TIAM.Database/DbSets/Users/IUserDbSet.cs index fbd819fc..ddc6b6f4 100644 --- a/TIAM.Database/DbSets/Users/IUserDbSet.cs +++ b/TIAM.Database/DbSets/Users/IUserDbSet.cs @@ -5,6 +5,6 @@ using TIAM.Entities.Users; namespace TIAM.Database.DbSets.Users; -public interface IUserDbSet : IAcUserDbSet +public interface IUserDbSet : IAcUserDbSet { } \ No newline at end of file diff --git a/TIAM.Database/ModelBuilders/Users/UserEntityTypeConfigurations.cs b/TIAM.Database/ModelBuilders/Users/UserEntityTypeConfigurations.cs index d8f4284b..ea6857b6 100644 --- a/TIAM.Database/ModelBuilders/Users/UserEntityTypeConfigurations.cs +++ b/TIAM.Database/ModelBuilders/Users/UserEntityTypeConfigurations.cs @@ -16,7 +16,7 @@ public class UserProductMappingEntityTypeDefaultConfiguration : IAcEntityTypeCon } } -public class UserEntityTypeDefaultConfiguration : AcUserEntityTypeDefaultConfiguration //IAcEntityTypeConfiguration// +public class UserEntityTypeDefaultConfiguration : AcUserEntityTypeDefaultConfiguration //IAcEntityTypeConfiguration// { public override void Configure(EntityTypeBuilder builder) { diff --git a/TIAM.Entities/ServiceProviders/ServiceProvider.cs b/TIAM.Entities/ServiceProviders/ServiceProvider.cs index 94e649a5..546222f4 100644 --- a/TIAM.Entities/ServiceProviders/ServiceProvider.cs +++ b/TIAM.Entities/ServiceProviders/ServiceProvider.cs @@ -4,11 +4,12 @@ using AyCode.Entities.ServiceProviders; using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; using TIAM.Entities.Products; +using TIAM.Entities.Users; namespace TIAM.Entities.ServiceProviders; [Table("ServiceProviders")] -public class TiamServiceProvider : AcServiceProvider +public class TiamServiceProvider : AcServiceProvider { public virtual List Products { get; } = new(); diff --git a/TIAM.Entities/Users/IUser.cs b/TIAM.Entities/Users/IUser.cs index ba90bb56..442d2964 100644 --- a/TIAM.Entities/Users/IUser.cs +++ b/TIAM.Entities/Users/IUser.cs @@ -5,7 +5,7 @@ using TIAM.Entities.ServiceProviders; namespace TIAM.Entities.Users; -public interface IUser : IAcUser, IUserDto +public interface IUser : IAcUser, IUserDto { public List Products { get; } diff --git a/TIAM.Entities/Users/IUserDto.cs b/TIAM.Entities/Users/IUserDto.cs index c6dae471..3d953cad 100644 --- a/TIAM.Entities/Users/IUserDto.cs +++ b/TIAM.Entities/Users/IUserDto.cs @@ -6,5 +6,5 @@ using TIAM.Entities.ServiceProviders; namespace TIAM.Entities.Users; -public interface IUserDto : IAcUserDtoBase +public interface IUserDto : IAcUserDtoBase { } \ No newline at end of file diff --git a/TIAM.Entities/Users/User.cs b/TIAM.Entities/Users/User.cs index bfb41aa7..ba921f91 100644 --- a/TIAM.Entities/Users/User.cs +++ b/TIAM.Entities/Users/User.cs @@ -11,7 +11,7 @@ using TIAM.Entities.ServiceProviders; namespace TIAM.Entities.Users { - public class User : AcUser, IUser + public class User : AcUser, IUser { public virtual List Products { get; } = new(); diff --git a/TIAM.Entities/Users/UserProductMapping.cs b/TIAM.Entities/Users/UserProductMapping.cs index 02792d8e..35350235 100644 --- a/TIAM.Entities/Users/UserProductMapping.cs +++ b/TIAM.Entities/Users/UserProductMapping.cs @@ -15,9 +15,7 @@ public class UserProductMapping : IEntityGuid, ITimeStampInfo public Guid UserId { get; set; } public Guid ProductId { get; set; } - [JsonIgnore] public virtual User User { get; set; } - [JsonIgnore] public virtual Product Product { get; set; } public DateTime Created { get; set; } diff --git a/TIAM.Entities/Users/UserToServiceProvider.cs b/TIAM.Entities/Users/UserToServiceProvider.cs new file mode 100644 index 00000000..fd8b254a --- /dev/null +++ b/TIAM.Entities/Users/UserToServiceProvider.cs @@ -0,0 +1,9 @@ +using AyCode.Entities.Users; +using TIAM.Entities.ServiceProviders; + +namespace TIAM.Entities.Users; + +public class UserToServiceProvider : AcUserToServiceProvider +{ + +} \ No newline at end of file diff --git a/TIAM.Models/Dtos/Users/UserDto.cs b/TIAM.Models/Dtos/Users/UserDto.cs index 39738236..a82eb157 100644 --- a/TIAM.Models/Dtos/Users/UserDto.cs +++ b/TIAM.Models/Dtos/Users/UserDto.cs @@ -11,4 +11,5 @@ public class UserDto : IUserDto public Guid ProfileId { get; } public Profile Profile { get; set; } public List ServiceProviders { get; set; } + public List UserToServiceProviders { get; set; } } \ No newline at end of file diff --git a/TIAM.Models/Dtos/Users/UserModelDto.cs b/TIAM.Models/Dtos/Users/UserModelDto.cs index 4504a1ae..aa3020f5 100644 --- a/TIAM.Models/Dtos/Users/UserModelDto.cs +++ b/TIAM.Models/Dtos/Users/UserModelDto.cs @@ -9,14 +9,23 @@ using TIAM.Models.Dtos.Profiles; namespace TIAM.Models.Dtos.Users; -public class UserModelDto : AcUserModelDtoBase +public class UserModelDto : AcUserModelDtoBase { - public List UserProductMappings = new(); - public List Products = new(); + public List UserProductMappings; + public List Products; public UserModelDto(){} public UserModelDto(User user) : base(user) { + if (user.Products.Count == 0) return; + + //így proxy error lesz... - J. + //Products = new List(user.Products); + //UserProductMappings = new List(user.UserProductMappings); + + Products = new List(user.Products.Count); + UserProductMappings = new List(user.UserProductMappings.Count); + foreach (var product in user.Products) { Products.Add(new Product(product.Id, product.ServiceProviderId, product.ProductType, product.Name, product.Description, product.Price, product.JsonDetails)); diff --git a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj index 854b012c..c19d133c 100644 --- a/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj +++ b/TIAMWebApp/Shared/TIAMWebApp.Shared.Application.csproj @@ -18,7 +18,6 @@ -