This commit is contained in:
jozsef.b@aycode.com 2023-12-22 09:50:07 +01:00
parent 35b9a07265
commit 3bd43a0f0a
7 changed files with 52 additions and 15 deletions

View File

@ -12,6 +12,7 @@ using TIAM.Database.DbContexts.ServiceProviders;
using TIAM.Database.DbSets.Permissions; using TIAM.Database.DbSets.Permissions;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.Test namespace TIAM.Database.Test
{ {
@ -105,6 +106,37 @@ namespace TIAM.Database.Test
Assert.IsNotNull(userProductMapping.Product, "Product is null"); 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<UserModelDto>(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] //[TestMethod]
//[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] //[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
//public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) //public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)

View File

@ -36,6 +36,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude)); 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 UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId));
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId));
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email)); public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude));

View File

@ -33,6 +33,7 @@ namespace TIAM.Database.DataLayers.Users
return Context.Users.ToListAsync(); return Context.Users.ToListAsync();
} }
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId));
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId)); public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId));
public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email)); public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email));
public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList()); public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList());

View File

@ -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<UserProductMapping> UserProductMappings { get; set; }
public List<Product> Products { get; set; }
}

View File

@ -9,10 +9,10 @@ using TIAM.Models.Dtos.Profiles;
namespace TIAM.Models.Dtos.Users; namespace TIAM.Models.Dtos.Users;
public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto, TiamServiceProvider, UserToServiceProvider> public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto, TiamServiceProvider, UserToServiceProvider>, IProductRelation
{ {
public List<UserProductMapping> UserProductMappings; public List<UserProductMapping> UserProductMappings { get; set; }
public List<Product> Products; public List<Product> Products { get; set; }
public UserModelDto(){} public UserModelDto(){}
public UserModelDto(User user) : base(user) public UserModelDto(User user) : base(user)

View File

@ -43,11 +43,6 @@ namespace TIAMWebApp.Client.Services
if (userModelDto != null) if (userModelDto != null)
{ {
var a = userModelDto.UserProductMappings.FirstOrDefault()?.Product;
if (a != null)
logToBrowserConsole.LogToBC($"{a.Name}");
//get user's properties //get user's properties
var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(userModelDto.Id); var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(userModelDto.Id);
@ -145,9 +140,11 @@ namespace TIAMWebApp.Client.Services
{ {
var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}"; var url = $"{Setting.BaseUrl}/{APIUrls.GetUserById}";
logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + id.ToString()); logToBrowserConsole.LogToBC("GetUserByIdAsync url: " + url + ", " + id.ToString());
var response = await http.PostAsJsonAsync(url, id); var response = await http.PostAsJsonAsync(url, id);
var result = await response.Content.ReadAsStringAsync(); var result = await response.Content.ReadAsStringAsync();
var user = JsonConvert.DeserializeObject<UserModelDto>(result); var user = JsonConvert.DeserializeObject<UserModelDto>(result);
return user; return user;
} }

View File

@ -344,13 +344,7 @@ namespace TIAMWebApp.Server.Controllers
public Task<UserModelDto?> GetUserById([FromBody] Guid id) public Task<UserModelDto?> GetUserById([FromBody] Guid id)
{ {
Logger.Info($"GetUserById called with id: {id}"); Logger.Info($"GetUserById called with id: {id}");
var result = _userDal.GetUserModelDtoByIdAsync(id); return _userDal.GetUserModelDtoByIdAsync(id);
//var b = result.UserProductMappings.FirstOrDefault(x => x.Id != null);
//var a = JsonSerializer.Serialize(result);
//Console.WriteLine($"GetUserById result: {a}");
return result;
} }
private bool VerifyPassword(string password, string hashedPassword) private bool VerifyPassword(string password, string hashedPassword)