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.

45 lines
1.5 KiB

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