Na, majd otthon ...

This commit is contained in:
Iván Szabó
2025-01-06 12:49:34 +01:00
parent a80870b5c3
commit 92801fefb9
11 changed files with 106 additions and 18 deletions
+10 -6
View File
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
@@ -8,24 +9,27 @@ using WorkFlowCheck.BL.DTO;
namespace WorkFlowCheck.MAUI.Services
{
public class UserService
public class UserService : IUserService
{
private readonly HttpClient _httpClient;
public UserService(HttpClient httpClient)
public UserService(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient;
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
_httpClient.BaseAddress = new Uri("https://192.168.50.128:5069");
// Alapértelmezett fejléc beállítása az API-kulccsal
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
//_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");
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", "RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU=");
}
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
{
try
{
// Az API végpont meghatározása
string endpoint = "api/user";
string endpoint = $"{_httpClient.BaseAddress}api/User";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);