fixes
This commit is contained in:
parent
35b9a07265
commit
3bd43a0f0a
|
|
@ -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<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]
|
||||
//[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||
//public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
|
||||
|
|
|
|||
|
|
@ -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<UserModelDto?> 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));
|
||||
|
|
|
|||
|
|
@ -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<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId));
|
||||
public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email) => SessionAsync(x => x.GetUserModelDtoByEmail(email));
|
||||
public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList());
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
}
|
||||
|
|
@ -9,10 +9,10 @@ using TIAM.Models.Dtos.Profiles;
|
|||
|
||||
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<Product> Products;
|
||||
public List<UserProductMapping> UserProductMappings { get; set; }
|
||||
public List<Product> Products { get; set; }
|
||||
|
||||
public UserModelDto(){}
|
||||
public UserModelDto(User user) : base(user)
|
||||
|
|
|
|||
|
|
@ -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<UserModelDto>(result);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,13 +344,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
public Task<UserModelDto?> 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue