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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user