Some other func
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DTO;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
public UserService(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
|
||||
// Alapértelmezett fejléc beállítása az API-kulccsal
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
|
||||
// Ha egyéni fejlécet használsz:
|
||||
// _httpClient.DefaultRequestHeaders.Add("X-Api-Key", "YOUR_API_KEY");
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Az API végpont meghatározása
|
||||
string endpoint = "api/user";
|
||||
|
||||
// HTTP GET kérés küldése
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Hiba visszaadása
|
||||
return new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
|
||||
@@ -64,6 +66,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Plugin.NFC\Plugin.NFC.csproj" />
|
||||
<ProjectReference Include="..\WorkFlowCheck.BL\WorkFlowCheck.BL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user