You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.5 KiB

using FluentBlazorApp.DTOs;
using FluentBlazorApp.Responses;
using FluentBlazorApp.States;
using System.Net.Http;
using System.Net.Http.Headers;
using static FluentBlazorApp.Responses.CustomResponses;
namespace FluentBlazorApp.Services
{
public class AccountService : IAccountService
{
private readonly HttpClient _httpClient;
private readonly string BASE_URL = "api/account";
public AccountService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<LoginResponse> LoginAsync(LoginDTO model)
{
var resonse = await _httpClient.PostAsJsonAsync($"{BASE_URL}/login", model);
var result = await resonse.Content.ReadFromJsonAsync<LoginResponse>();
return result;
}
public async Task<RegistrationResonse> RegisterAsync(RegisterDTO model)
{
var resonse = await _httpClient.PostAsJsonAsync($"{BASE_URL}/register", model);
var result = await resonse.Content.ReadFromJsonAsync<RegistrationResonse>();
return result;
}
public async Task<WeatherForecastDTO[]> GetWeatherForecastsAync()
{
if (string.IsNullOrWhiteSpace(Constants.JWTToken))
return null;
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants.JWTToken);
return await _httpClient.GetFromJsonAsync<WeatherForecastDTO[]>($"{BASE_URL}/weather");
}
}
}