Changing UserDataServiceClientBase Http to Signalr in progress...

This commit is contained in:
Loretta 2024-08-29 16:40:46 +02:00
parent 2b11c329af
commit 5bc9663930
8 changed files with 221 additions and 182 deletions

View File

@ -113,8 +113,13 @@ public class SignalRTags : AcSignalRTags
public const int GetTransferDestinationToProductsByTransferDestinationId = 96; public const int GetTransferDestinationToProductsByTransferDestinationId = 96;
public const int GetAllUsers = 120; public const int GetAllUsers = 120;
public const int GetAllUserModelDtoDetails = 121; public const int GetAllUserModelDto = 121;
public const int GetAllUserModelDtoEmails = 125; public const int GetAllUserModelDtoDetails = 122;
public const int GetAllUserModelDtoEmails = 123;
public const int GetUserModelDtoById = 126;
public const int GetUserModelDtoByEmail = 127;
public const int GetUserModelDtoDetailById = 128;
public const int GetUserModelDtoDetailByEmail = 129;
public const int AddUser = 130; public const int AddUser = 130;
public const int AddUserModelDtoDetail = 131; public const int AddUserModelDtoDetail = 131;
public const int UpdateUser = 135; public const int UpdateUser = 135;
@ -125,5 +130,6 @@ public class SignalRTags : AcSignalRTags
public const int GuestUpdateTransfer = 150; public const int GuestUpdateTransfer = 150;
public const int DriverUpdateTransfer = 151; public const int DriverUpdateTransfer = 151;
public const int AuthenticateUser = 160;
public const int GetAllLogItemsByFilterText = 1000; public const int GetAllLogItemsByFilterText = 1000;
} }

View File

@ -17,7 +17,7 @@ using TIAMWebApp.Shared.Application.Utility;
namespace TIAMMobileApp.Services namespace TIAMMobileApp.Services
{ {
public class UserDataServiceMobile(HttpClient http, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters) public class UserDataServiceMobile(HttpClient http, AdminSignalRClient adminSignalRClient, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters)
: UserDataServiceClientBase(http, sessionService, secureStorageHandler, serviceProviderDataService, logWriters); : UserDataServiceClientBase(http, adminSignalRClient, sessionService, secureStorageHandler, serviceProviderDataService, logWriters);
} }

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using System.Text.Json; using System.Text.Json;
using AyCode.Core.Extensions;
using AyCode.Core.Helpers; using AyCode.Core.Helpers;
using TIAMWebApp.Shared.Application.Models.ClientSide; using TIAMWebApp.Shared.Application.Models.ClientSide;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;
@ -64,22 +65,22 @@ namespace TIAMSharedUI.Pages
{ {
_currentStep = 1; _currentStep = 1;
BrowserConsoleLogWriter.Info("Login started: " + "Email: " + _loginModel.Email + ", Password: " + _loginModel.Password); BrowserConsoleLogWriter.Info("Login started: " + "Email: " + _loginModel.Email + ", Password: " + _loginModel.Password);
var response = await userDataService.AuthenticateUser(_loginModel);
var mainResponse = await userDataService.AuthenticateUser(_loginModel);
//var response = await UserDataservice.TestUserApi(30); //var response = await UserDataservice.TestUserApi(30);
BrowserConsoleLogWriter.Info("Login started"); BrowserConsoleLogWriter.Info("Login started");
BrowserConsoleLogWriter.Info(response); //BrowserConsoleLogWriter.Info(response);
if (!string.IsNullOrEmpty(response)) //if (!string.IsNullOrEmpty(response))
if (mainResponse != null)
{ {
//get token and save to local storage //get token and save to local storage
//parse to Mainresponse from json string //parse to Mainresponse from json string
//var Mainresponse = JsonSerializer.Deserialize<MainResponse>(response); //var Mainresponse = JsonSerializer.Deserialize<MainResponse>(response);
var mainResponse = JsonSerializer.Deserialize<MainResponse>(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); //var mainResponse = JsonSerializer.Deserialize<MainResponse>(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
if (mainResponse != null)
{
if (!mainResponse.IsSuccess) if (!mainResponse.IsSuccess)
{ {
@ -93,9 +94,9 @@ namespace TIAMSharedUI.Pages
} }
else else
{ {
string authResponseJson = JsonSerializer.Serialize(mainResponse.Content); string authResponseJson = mainResponse.Content.ToJson(); //JsonSerializer.Serialize(mainResponse.Content);
var authResponse = JsonSerializer.Deserialize<AuthenticationResponse>(authResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); var authResponse = authResponseJson.JsonTo<AuthenticationResponse>(); //JsonSerializer.Deserialize<AuthenticationResponse>(authResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
string accessToken = authResponse.AccessToken; string accessToken = authResponse.AccessToken;
@ -139,16 +140,14 @@ namespace TIAMSharedUI.Pages
navManager.NavigateTo("/"); navManager.NavigateTo("/");
} }
} }
}
else else
{ {
//api error //api error
//await App.Current.MainPage.DisplayAlert("Error", "An error occured while trying to login", "Ok"); //await App.Current.MainPage.DisplayAlert("Error", "An error occured while trying to login", "Ok");
//display error message via jsinterop //display error message via jsinterop
BrowserConsoleLogWriter.Info("An error occured while trying to login"); BrowserConsoleLogWriter.Warning("An error occured while trying to login");
navManager.NavigateTo("login"); navManager.NavigateTo("login");
} }
} }
protected override void OnInitialized() protected override void OnInitialized()

View File

@ -19,7 +19,7 @@ using TIAMWebApp.Shared.Application.Services;
namespace TIAMWebApp.Client.Services namespace TIAMWebApp.Client.Services
{ {
public class UserDataServiceWeb(HttpClient http, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters) public class UserDataServiceWeb(HttpClient http, AdminSignalRClient adminSignalRClient, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters)
: UserDataServiceClientBase(http, sessionService, secureStorageHandler, serviceProviderDataService, logWriters); : UserDataServiceClientBase(http, adminSignalRClient, sessionService, secureStorageHandler, serviceProviderDataService, logWriters);
} }

View File

@ -96,11 +96,27 @@ namespace TIAMWebApp.Server.Controllers
if (authenticateUser == null) throw new NullReferenceException("authenticateUser == null"); if (authenticateUser == null) throw new NullReferenceException("authenticateUser == null");
_logger.Info(authenticateUser.Email); var response = await AuthenticateUser(authenticateUser);
var loggedInModel = _loginService.Login(authenticateUser.Email, authenticateUser.Password); if (response != null) return Ok(response);
if (loggedInModel.IsLoggedIn)
return Unauthorized();
}
[NonAction]
[SignalR(SignalRTags.AuthenticateUser)]
public async Task<MainResponse?> AuthenticateUser(LoginModel authenticateUser)
{ {
_logger.Info($"AuthenticateUser; {authenticateUser.Email}");
var loggedInModel = await _loginService.LoginAsync(authenticateUser.Email, authenticateUser.Password);
if (!loggedInModel.IsLoggedIn)
{
_logger.Warning(@"User not valid! errorCode: " + loggedInModel.LoginErrorCode);
return null;
}
var response = new MainResponse var response = new MainResponse
{ {
Content = new AuthenticationResponse Content = new AuthenticationResponse
@ -113,11 +129,7 @@ namespace TIAMWebApp.Server.Controllers
ErrorMessage = "" ErrorMessage = ""
}; };
return Ok(response); return response;
}
_logger.Warning(@"User not valid! errorCode: " + loggedInModel.LoginErrorCode);
return Unauthorized();
} }
[AllowAnonymous] [AllowAnonymous]
@ -199,7 +211,7 @@ namespace TIAMWebApp.Server.Controllers
else else
{ {
var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>(); var user = JObject.Parse(serializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
bool result = false; var result = false;
if (user != null) if (user != null)
{ {
//add userModel to users array //add userModel to users array
@ -297,6 +309,7 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route("GetUsers")] [Route("GetUsers")]
[SignalR(SignalRTags.GetAllUserModelDto)]
public async Task<List<UserModelDto>> GetUsers() public async Task<List<UserModelDto>> GetUsers()
{ {
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync(); //var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
@ -412,34 +425,35 @@ namespace TIAMWebApp.Server.Controllers
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route(APIUrls.GetUserByEmailRouteName + "/{email}")] [Route(APIUrls.GetUserByEmailRouteName + "/{email}")]
public async Task<UserModelDto>? GetUserByEmail(string email) [SignalR(SignalRTags.GetUserModelDtoByEmail)]
public async Task<UserModelDto?> GetUserByEmail(string email)
{ {
_logger.Info($"GetUserByEmail called with email: {email}"); _logger.Info($"GetUserByEmail called with email: {email}");
var result = await userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
if (result == null)
{
UserModelDto resultDto = new UserModelDto();
return resultDto;
}
else
{
return result;
}
return await userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
//var result = await userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
//if (result != null) return result;
//var resultDto = new UserModelDto();
//return resultDto;
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserByIdRouteName)] [Route(APIUrls.GetUserByIdRouteName)]
[SignalR(SignalRTags.GetUserModelDtoById)]
public async Task<UserModelDto?> GetUserById([FromBody] Guid id) public async Task<UserModelDto?> GetUserById([FromBody] Guid id)
{ {
_logger.Info($"GetUserById called with id: {id}"); _logger.Info($"GetUserById called with id: {id}");
return await userDal.GetUserModelDtoByIdAsync<UserModelDto>(id, true); return await userDal.GetUserModelDtoByIdAsync<UserModelDto>(id, true);
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserDetailByIdRouteName)] [Route(APIUrls.GetUserDetailByIdRouteName)]
[SignalR(SignalRTags.GetUserModelDtoDetailById)]
public async Task<UserModelDtoDetail?> GetUserDetailById([FromBody] Guid id) public async Task<UserModelDtoDetail?> GetUserDetailById([FromBody] Guid id)
{ {
_logger.Info($"GetUserDetailById called with id: {id}"); _logger.Info($"GetUserDetailById called with id: {id}");

View File

@ -8,14 +8,14 @@ namespace TIAMWebApp.Shared.Application.Interfaces
{ {
public Task<UserSessionModel> IsLoggedInAsync(Guid id); public Task<UserSessionModel> IsLoggedInAsync(Guid id);
public Task<string> AuthenticateUser(LoginModel loginModel); public Task<MainResponse?> AuthenticateUser(LoginModel loginModel);
public Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel); public Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel);
public Task<(bool isSuccess, UserModelDto? user)> CreateGuestUser(RegistrationModel regModel); public Task<(bool isSuccess, UserModelDto? user)> CreateGuestUser(RegistrationModel regModel);
public Task<string> TestUserApi(int Param); public Task<string> TestUserApi(int Param);
//public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel); //public Task<Dictionary<int, string>> GetUserRolesAsync(UserModel userModel);
public Task<List<UserModelDto>?> GetUsersAsync(); public Task<List<UserModelDto>> GetUsersAsync();
public Task<List<UserModelDtoDetail>> GetUsersWithDetailsAsync(); public Task<List<UserModelDtoDetail>> GetUsersWithDetailsAsync();

View File

@ -23,12 +23,7 @@ public abstract class SessionServiceClientBase : ISessionService
public virtual List<Product> GetHotels() public virtual List<Product> GetHotels()
{ {
if (User != null) return User != null ? User.UserModelDto.Products.Where(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel).ToList() : [];
{
return User.UserModelDto.Products.Count > 0 ? User.UserModelDto.Products.Where(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel).ToList() : [];
}
return [];
} }
public virtual void ClearAll() public virtual void ClearAll()

View File

@ -5,6 +5,7 @@ using AyCode.Interfaces.StorageHandlers;
using AyCode.Services.Loggers; using AyCode.Services.Loggers;
using Newtonsoft.Json; using Newtonsoft.Json;
using TIAM.Models.Dtos.Users; using TIAM.Models.Dtos.Users;
using TIAM.Services;
using TIAMWebApp.Shared.Application.Interfaces; using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide; using TIAMWebApp.Shared.Application.Models.ClientSide;
@ -17,15 +18,18 @@ public abstract class UserDataServiceClientBase : IUserDataService
{ {
protected readonly HttpClient Http; protected readonly HttpClient Http;
protected readonly LoggerClient Logger; protected readonly LoggerClient Logger;
protected readonly AdminSignalRClient AdminSignalRClient;
protected readonly ISessionService SessionService; protected readonly ISessionService SessionService;
protected readonly ISecureStorageHandler SecureStorageHandler; protected readonly ISecureStorageHandler SecureStorageHandler;
protected readonly IServiceProviderDataService ServiceProviderDataService; protected readonly IServiceProviderDataService ServiceProviderDataService;
protected UserDataServiceClientBase(HttpClient http, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters) protected UserDataServiceClientBase(HttpClient http, AdminSignalRClient adminSignalRClient, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters)
{ {
Http = http; Http = http;
AdminSignalRClient = adminSignalRClient;
SessionService = sessionService; SessionService = sessionService;
SecureStorageHandler = secureStorageHandler; SecureStorageHandler = secureStorageHandler;
@ -71,34 +75,37 @@ public abstract class UserDataServiceClientBase : IUserDataService
return result; return result;
} }
public async Task<string> AuthenticateUser(LoginModel loginModel) public async Task<MainResponse?> AuthenticateUser(LoginModel loginModel)
{ {
var result = string.Empty; Logger.Debug($"AuthenticateUser; email: {loginModel.Email}");
var url = $"{Setting.ApiBaseUrl}/{APIUrls.AuthenticateUser}";
var response = await Http.PostAsJsonAsync(url, loginModel); return await AdminSignalRClient.PostDataAsync<LoginModel, MainResponse>(SignalRTags.AuthenticateUser, loginModel);
//try //var result = string.Empty;
//var url = $"{Setting.ApiBaseUrl}/{APIUrls.AuthenticateUser}";
//var response = await Http.PostAsJsonAsync(url, loginModel);
////try
////{
//// Logger.Detail("Login started: " + "Email: " + loginModel.Email + ", Password: " + loginModel.Password);
////}
////catch (Exception ex)
////{
//// _logger.Error(ex.Message, ex);
////}
//if (response.IsSuccessStatusCode)
//{ //{
// Logger.Detail("Login started: " + "Email: " + loginModel.Email + ", Password: " + loginModel.Password);
//}
//catch (Exception ex)
//{
// _logger.Error(ex.Message, ex);
//}
if (response.IsSuccessStatusCode)
{
result = await response.Content.ReadAsStringAsync();
}
else
{
result = await response.Content.ReadAsStringAsync();
}
// result = await response.Content.ReadAsStringAsync(); // result = await response.Content.ReadAsStringAsync();
return result; //}
//else
//{
// result = await response.Content.ReadAsStringAsync();
//}
////result = await response.Content.ReadAsStringAsync();
//return result;
} }
public async Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel) public async Task<(bool isSuccess, string ErrorMessage)> CreateUser(RegistrationModel regModel)
@ -107,7 +114,7 @@ public abstract class UserDataServiceClientBase : IUserDataService
var result = string.Empty; var result = string.Empty;
var url = $"{Setting.ApiBaseUrl}/{APIUrls.CreateUser}"; var url = $"{Setting.ApiBaseUrl}/{APIUrls.CreateUser}";
Logger.Info("CreateUser url: " + url); Logger.Debug("CreateUser url: " + url);
var response = await Http.PostAsJsonAsync(url, regModel); var response = await Http.PostAsJsonAsync(url, regModel);
result = await response.Content.ReadAsStringAsync(); result = await response.Content.ReadAsStringAsync();
@ -133,7 +140,7 @@ public abstract class UserDataServiceClientBase : IUserDataService
var user = new UserModelDto(); var user = new UserModelDto();
var url = $"{Setting.ApiBaseUrl}/{APIUrls.CreateGuestUser}"; var url = $"{Setting.ApiBaseUrl}/{APIUrls.CreateGuestUser}";
Logger.Info("CreateGuestUser url: " + url); Logger.Debug("CreateGuestUser url: " + url);
var response = await Http.PostAsJsonAsync(url, regModel); var response = await Http.PostAsJsonAsync(url, regModel);
@ -141,7 +148,7 @@ public abstract class UserDataServiceClientBase : IUserDataService
{ {
isSuccess = true; isSuccess = true;
result = await response.Content.ReadAsStringAsync(); result = await response.Content.ReadAsStringAsync();
Logger.Info("CreateGuestUser result: " + result); Logger.Debug("CreateGuestUser result: " + result);
user = JsonConvert.DeserializeObject<UserModelDto>(result); user = JsonConvert.DeserializeObject<UserModelDto>(result);
} }
else else
@ -155,89 +162,107 @@ public abstract class UserDataServiceClientBase : IUserDataService
} }
public async Task<List<UserModelDto>?> GetUsersAsync() public async Task<List<UserModelDto>> GetUsersAsync()
{ {
return await Http.GetFromJsonAsync<List<UserModelDto>>(APIUrls.GetUsers); Logger.Debug($"GetUsersAsync");
return await AdminSignalRClient.GetAllAsync<List<UserModelDto>>(SignalRTags.GetAllUserModelDto) ?? [];
//return await Http.GetFromJsonAsync<List<UserModelDto>>(APIUrls.GetUsers);
} }
public async Task<List<UserModelDtoDetail>> GetUsersWithDetailsAsync() public async Task<List<UserModelDtoDetail>> GetUsersWithDetailsAsync()
{ {
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUsersWithDetails}"; Logger.Debug($"GetUsersWithDetailsAsync");
Logger.Info("GetUserByEmailAsync url: " + url + "!"); return await AdminSignalRClient.GetAllAsync<List<UserModelDtoDetail>>(SignalRTags.GetAllUserModelDtoDetails) ?? [];
var response = await Http.GetFromJsonAsync<List<UserModelDtoDetail>>(APIUrls.GetUsersWithDetails);
//var result = await response.Content.ReadAsStringAsync();
//var user = JsonConvert.DeserializeObject<UserModelDto>(result);
return response ?? []; ////var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUsersWithDetails}";
////Logger.Info("GetUserByEmailAsync url: " + url + "!");
////var response = await Http.GetFromJsonAsync<List<UserModelDtoDetail>>(APIUrls.GetUsersWithDetails);
//////var result = await response.Content.ReadAsStringAsync();
//////var user = JsonConvert.DeserializeObject<UserModelDto>(result);
////return response ?? [];
} }
public async Task<UserModelDto?> GetUserByEmailAsync(string email) public async Task<UserModelDto?> GetUserByEmailAsync(string email)
{ {
try Logger.Debug($"GetUserByEmailAsync; email: {email}");
{
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserByEmail}/{email}";
Logger.Info("GetUserByEmailAsync url: " + url + ", " + email);
var response = await Http.GetAsync(url); return await AdminSignalRClient.GetByIdAsync<UserModelDto>(SignalRTags.GetUserModelDtoByEmail, email);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode) //try
{ //{
var jsonResponse = await response.Content.ReadAsStringAsync(); // var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserByEmail}/{email}";
var user = System.Text.Json.JsonSerializer.Deserialize<UserModelDto>(jsonResponse, new JsonSerializerOptions // Logger.Info("GetUserByEmailAsync url: " + url + ", " + email);
{
PropertyNameCaseInsensitive = true
});
return user;
}
return null; // var response = await Http.GetAsync(url);
} // response.EnsureSuccessStatusCode();
catch (HttpRequestException httpRequestException)
{ // if (response.IsSuccessStatusCode)
// Handle specific HTTP request exceptions // {
Logger.DebugConditional($"Request error: {httpRequestException.Message}"); // var jsonResponse = await response.Content.ReadAsStringAsync();
throw; // var user = System.Text.Json.JsonSerializer.Deserialize<UserModelDto>(jsonResponse, new JsonSerializerOptions
} // {
catch (Exception ex) // PropertyNameCaseInsensitive = true
{ // });
// Handle other possible exceptions // return user;
Logger.DebugConditional($"An error occurred: {ex.Message}"); // }
throw;
} // return null;
//}
//catch (HttpRequestException httpRequestException)
//{
// // Handle specific HTTP request exceptions
// Logger.DebugConditional($"Request error: {httpRequestException.Message}");
// throw;
//}
//catch (Exception ex)
//{
// // Handle other possible exceptions
// Logger.DebugConditional($"An error occurred: {ex.Message}");
// throw;
//}
} }
public async Task<UserModelDto?> GetUserByIdAsync(Guid id) public async Task<UserModelDto?> GetUserByIdAsync(Guid id)
{ {
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserById}"; Logger.Debug($"GetUserByIdAsync; id: {id}");
Logger.Info("GetUserByIdAsync url: " + url + ", " + id.ToString());
var response = await Http.PostAsJsonAsync(url, id); return await AdminSignalRClient.GetByIdAsync<UserModelDto>(SignalRTags.GetUserModelDtoById, id);
var result = await response.Content.ReadAsStringAsync();
var user = JsonConvert.DeserializeObject<UserModelDto>(result);
return user; //var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserById}";
//Logger.Debug("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;
} }
public async Task<UserModelDtoDetail?> GetUserDetailByIdAsync(Guid id) public async Task<UserModelDtoDetail?> GetUserDetailByIdAsync(Guid id)
{ {
Logger.Info("GetUserDetailByIdAsync", "GLOBAL_LOGGER"); Logger.Debug($"GetUserDetailByIdAsync; id: {id}");
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserDetailById}"; return await AdminSignalRClient.GetByIdAsync<UserModelDtoDetail>(SignalRTags.GetUserModelDtoDetailById, id);
Logger.Info("GetUserDetailByIdAsync url: " + url + ", " + id.ToString());
var response = await Http.PostAsJsonAsync(url, id); //var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserDetailById}";
//var result = await response.Content.ReadAsStringAsync(); //Logger.Info("GetUserDetailByIdAsync url: " + url + ", " + id.ToString());
var result = await response.Content.ReadFromJsonAsync<UserModelDtoDetail>();
//var user = JsonConvert.DeserializeObject<UserModelDtoDetail>(result);
return result; //var response = await Http.PostAsJsonAsync(url, id);
////var result = await response.Content.ReadAsStringAsync();
//var result = await response.Content.ReadFromJsonAsync<UserModelDtoDetail>();
////var user = JsonConvert.DeserializeObject<UserModelDtoDetail>(result);
//return result;
} }
public async Task<bool> RefreshToken() public async Task<bool> RefreshToken()
{ {
Logger.Info("RefreshToken() called"); Logger.Debug("RefreshToken() called");
var isTokenRefreshed = false; var isTokenRefreshed = false;
var url = $"{Setting.ApiBaseUrl}/{APIUrls.RefreshToken}"; var url = $"{Setting.ApiBaseUrl}/{APIUrls.RefreshToken}";
@ -251,7 +276,7 @@ public abstract class UserDataServiceClientBase : IUserDataService
try try
{ {
Logger.Info("Refreshtoken url: " + url); Logger.Debug("Refreshtoken url: " + url);
var response = await Http.PostAsync(url, new StringContent(serializedStr, Encoding.UTF8, "application/json")); var response = await Http.PostAsync(url, new StringContent(serializedStr, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {