Some other func

This commit is contained in:
2025-01-06 08:58:17 +01:00
parent 8bbcbfab09
commit a80870b5c3
9 changed files with 118 additions and 19 deletions
@@ -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
};
}
}
}
}