getuserbyemail fix
This commit is contained in:
parent
a9febbf7a0
commit
a7ba221183
|
|
@ -1,5 +1,6 @@
|
|||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using AyCode.Interfaces.StorageHandlers;
|
||||
using AyCode.Services.Loggers;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -20,9 +21,8 @@ namespace TIAMMobileApp.Services
|
|||
private readonly HttpClient http;
|
||||
private readonly ISecureStorageHandler secureStorageHandler;
|
||||
private readonly IServiceProviderDataService serviceProviderDataService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly LoggerClient<UserDataServiceMobile> _logger;
|
||||
|
||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public UserDataServiceMobile(HttpClient http, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters)
|
||||
{
|
||||
|
|
@ -183,18 +183,48 @@ namespace TIAMMobileApp.Services
|
|||
|
||||
public async Task<UserModelDto?> GetUserByEmailAsync(string email)
|
||||
{
|
||||
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserByEmail}";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserByEmail}/{email}";
|
||||
_logger.Info("GetUserByEmailAsync url: " + url + ", " + email);
|
||||
//GlobalLogger.Info("GetUserByEmailAsync url: " + url + ", " + email, "GLOBAL_LOGGER");
|
||||
var response = await http.GetAsync(url);
|
||||
|
||||
|
||||
var response = await http.PostAsJsonAsync(url, email);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
var user = JsonConvert.DeserializeObject<UserModelDto>(result);
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (response.Content != null)
|
||||
{
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
var user = System.Text.Json.JsonSerializer.Deserialize<UserModelDto>(jsonResponse, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
return user;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserById}";
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ using TIAMWebApp.Shared.Application.Utility;
|
|||
using AyCode.Interfaces.StorageHandlers;
|
||||
using TIAM.Models.Dtos.Users;
|
||||
using AyCode.Services.Loggers;
|
||||
using System.Net.Http;
|
||||
using AyCode.Core.Extensions;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
namespace TIAMWebApp.Client.Services
|
||||
|
|
@ -22,7 +25,6 @@ namespace TIAMWebApp.Client.Services
|
|||
private readonly LoggerClient<UserDataServiceWeb> _logger;
|
||||
|
||||
|
||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public UserDataServiceWeb(HttpClient http, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable<IAcLogWriterClientBase> logWriters)
|
||||
//public UserDataServiceWeb(HttpClient http, ISecureStorageHandler secureStorageHandler, IJSRuntime jSRuntime, IServiceProviderDataService serviceProviderDataService, HttpClientLogItemWriter logWriter)
|
||||
|
|
@ -185,17 +187,47 @@ namespace TIAMWebApp.Client.Services
|
|||
}
|
||||
|
||||
public async Task<UserModelDto?> GetUserByEmailAsync(string email)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetUserByEmail}/{email}";
|
||||
|
||||
_logger.Info("GetUserByEmailAsync url: " + url + ", " + email);
|
||||
//GlobalLogger.Info("GetUserByEmailAsync url: " + url + ", " + email, "GLOBAL_LOGGER");
|
||||
var response = await http.GetAsync(url);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (response.Content != null)
|
||||
{
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
var user = System.Text.Json.JsonSerializer.Deserialize<UserModelDto>(jsonResponse, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
return user;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var response = (UserModelDto)(await http.GetFromJsonAsync(url,typeof (UserModelDto)));
|
||||
|
||||
//var user = JsonConvert.DeserializeObject<UserModelDto>(result);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<UserModelDto?> GetUserByIdAsync(Guid id)
|
||||
|
|
|
|||
|
|
@ -358,10 +358,20 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
[Route(APIUrls.GetUserByEmailRouteName + "/{email}")]
|
||||
public Task<UserModelDto?> GetUserByEmail(string email)
|
||||
public async Task<UserModelDto>? GetUserByEmail(string email)
|
||||
{
|
||||
_logger.Info($"GetUserByEmail called with email: {email}");
|
||||
return _userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
|
||||
var result = _userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
|
||||
if (result.Result == null)
|
||||
{
|
||||
UserModelDto resultDto = new UserModelDto();
|
||||
return resultDto;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result.Result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ namespace TIAMWebApp.Shared.Application.Interfaces
|
|||
{
|
||||
public interface IUserDataService
|
||||
{
|
||||
public Dictionary<int, string> userRoleTypes { get; set; }
|
||||
|
||||
public Task<UserSessionModel> IsLoggedInAsync(Guid id);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue