User továbbgondolása

This commit is contained in:
2025-03-17 12:10:41 +01:00
parent 0e06382eee
commit 8c1e60889d
11 changed files with 306 additions and 44 deletions
@@ -4,18 +4,18 @@ namespace WorkFlowCheck.Web.Services.Interfaces
{
public interface IUserService
{
Task<ApiRequestDTO<UserDTO>> GetUser(int id);
Task<ApiRequestDTO<List<UserDTO>>> GetAllUsers();
Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO user);
Task<UserDTO> GetUser(int id);
Task<List<UserDTO>> GetAllUsers();
Task<UserDTO> UpdateUser(UserDTO user);
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
Task<ApiRequestDTO<RoleDTO>> GetRole(int id);
Task<ApiRequestDTO<List<RoleDTO>>> GetAllRoles();
Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO role);
Task<RoleDTO> GetRole(int id);
Task<List<RoleDTO>> GetAllRoles();
Task<RoleDTO> UpdateRole(RoleDTO role);
Task<ApiRequestDTO<UserRoleDTO>> GetUserRole(int id);
Task<ApiRequestDTO<List<UserDTO>>> GetAllUserRoles();
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRole);
Task<UserRoleDTO> GetUserRole(int id);
Task<List<UserDTO>> GetAllUserRoles();
Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole);
}
+59 -11
View File
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
@@ -15,23 +16,17 @@ namespace WorkFlowCheck.Web.Services
try
{
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/user/authenticate";
string endpoint = $"{_httpClient.BaseAddress}api/User/Authenticate";
var userDTO = new UserDTO()
var userSimpleDTO = new UserSimpleDTO()
{
Email = "",
FirstName = "",
LastName = "",
Id = 0,
UserName = username,
Password = password,
JwtToken = "",
RoleDTO = new List<RoleDTO>(),
};
// HTTP POST kérés küldése
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userDTO))
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userSimpleDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
@@ -53,5 +48,58 @@ namespace WorkFlowCheck.Web.Services
};
}
}
public Task<ApiRequestDTO<List<RoleDTO>>> GetAllRoles() => throw new NotImplementedException();
public Task<ApiRequestDTO<List<UserDTO>>> GetAllUserRoles() => throw new NotImplementedException();
public async Task<List<UserDTO>> GetAllUsers()
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUsers";
var retVal = new List<UserDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public Task<RoleDTO> GetRole(int id) => throw new NotImplementedException();
public async Task<UserDTO> GetUser(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetUser/{id}";
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public Task<UserRoleDTO> GetUserRole(int id) => throw new NotImplementedException();
public Task<RoleDTO> UpdateRole(RoleDTO role) => throw new NotImplementedException();
public Task<UserDTO> UpdateUser(UserDTO user) => throw new NotImplementedException();
public Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole) => throw new NotImplementedException();
Task<List<RoleDTO>> IUserService.GetAllRoles() => throw new NotImplementedException();
Task<List<UserDTO>> IUserService.GetAllUserRoles() => throw new NotImplementedException();
}
}