diff --git a/TIAM.Database.Test/ServiceProviderDalTest.cs b/TIAM.Database.Test/ServiceProviderDalTest.cs index 1c1e9e06..c40d4ce9 100644 --- a/TIAM.Database.Test/ServiceProviderDalTest.cs +++ b/TIAM.Database.Test/ServiceProviderDalTest.cs @@ -12,6 +12,7 @@ using TIAM.Database.DbContexts.ServiceProviders; using TIAM.Database.DbSets.Permissions; using TIAM.Entities.Products; using TIAM.Entities.Users; +using TIAM.Models.Dtos.Users; namespace TIAM.Database.Test { @@ -105,6 +106,37 @@ namespace TIAM.Database.Test Assert.IsNotNull(userProductMapping.Product, "Product is null"); } + [TestMethod] + [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] + [DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")] + [DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")] + public void SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) + { + var userId = Guid.Parse(userIdString); + + JsonSerializerSettings options = new() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore + }; + + var userModel = Dal.GetUserModelDtoById(userId); + + var serializedUserModel = JsonConvert.SerializeObject(userModel, options); + userModel = JsonConvert.DeserializeObject(serializedUserModel); + + Assert.IsNotNull(userModel); + Assert.IsNotNull(userModel.UserDto); + 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.UserProductMappings.Count > 0); + + Assert.IsTrue(userModel.ServiceProviders.Count > 0); + Assert.IsTrue(userModel.UserToServiceProviders.Count > 0); + } //[TestMethod] //[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] //public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) diff --git a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs index 38041400..ea952308 100644 --- a/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs +++ b/TIAM.Database/DataLayers/ServiceProviders/ServiceProviderDal.cs @@ -36,6 +36,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude)); public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); + public Task GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude)); diff --git a/TIAM.Database/DataLayers/Users/UserDal.cs b/TIAM.Database/DataLayers/Users/UserDal.cs index 642d8a25..5328ca5b 100644 --- a/TIAM.Database/DataLayers/Users/UserDal.cs +++ b/TIAM.Database/DataLayers/Users/UserDal.cs @@ -33,6 +33,7 @@ namespace TIAM.Database.DataLayers.Users return Context.Users.ToListAsync(); } + public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId)); public Task GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); public Task GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email)); public Task> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList()); diff --git a/TIAM.Entities/Products/IProductRelation.cs b/TIAM.Entities/Products/IProductRelation.cs new file mode 100644 index 00000000..bf605a9a --- /dev/null +++ b/TIAM.Entities/Products/IProductRelation.cs @@ -0,0 +1,12 @@ +using AyCode.Interfaces.ServiceProviders; +using AyCode.Interfaces.Users; +using TIAM.Entities.Users; + +namespace TIAM.Entities.Products; + +public interface IProductRelation +{ + public List UserProductMappings { get; set; } + public List Products { 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 aa3020f5..6a69f5f4 100644 --- a/TIAM.Models/Dtos/Users/UserModelDto.cs +++ b/TIAM.Models/Dtos/Users/UserModelDto.cs @@ -9,10 +9,10 @@ using TIAM.Models.Dtos.Profiles; namespace TIAM.Models.Dtos.Users; -public class UserModelDto : AcUserModelDtoBase +public class UserModelDto : AcUserModelDtoBase, IProductRelation { - public List UserProductMappings; - public List Products; + public List UserProductMappings { get; set; } + public List Products { get; set; } public UserModelDto(){} public UserModelDto(User user) : base(user) diff --git a/TIAMWebApp/Client/Services/UserDataServiceWeb.cs b/TIAMWebApp/Client/Services/UserDataServiceWeb.cs index 430d3786..1908a823 100644 --- a/TIAMWebApp/Client/Services/UserDataServiceWeb.cs +++ b/TIAMWebApp/Client/Services/UserDataServiceWeb.cs @@ -43,11 +43,6 @@ namespace TIAMWebApp.Client.Services if (userModelDto != null) { - var a = userModelDto.UserProductMappings.FirstOrDefault()?.Product; - - if (a != null) - logToBrowserConsole.LogToBC($"{a.Name}"); - //get user's properties var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(userModelDto.Id); @@ -145,9 +140,11 @@ namespace TIAMWebApp.Client.Services { var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}"; logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + id.ToString()); + var response = await http.PostAsJsonAsync(url, id); var result = await response.Content.ReadAsStringAsync(); var user = JsonConvert.DeserializeObject(result); + return user; } diff --git a/TIAMWebApp/Server/Controllers/UserAPIController.cs b/TIAMWebApp/Server/Controllers/UserAPIController.cs index d5f764d4..ccc7f62c 100644 --- a/TIAMWebApp/Server/Controllers/UserAPIController.cs +++ b/TIAMWebApp/Server/Controllers/UserAPIController.cs @@ -344,13 +344,7 @@ namespace TIAMWebApp.Server.Controllers public Task GetUserById([FromBody] Guid id) { Logger.Info($"GetUserById called with id: {id}"); - var result = _userDal.GetUserModelDtoByIdAsync(id); - - //var b = result.UserProductMappings.FirstOrDefault(x => x.Id != null); - //var a = JsonSerializer.Serialize(result); - //Console.WriteLine($"GetUserById result: {a}"); - - return result; + return _userDal.GetUserModelDtoByIdAsync(id); } private bool VerifyPassword(string password, string hashedPassword)