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 LoginAsync(LoginDTO model) { var resonse = await _httpClient.PostAsJsonAsync($"{BASE_URL}/login", model); var result = await resonse.Content.ReadFromJsonAsync(); return result; } public async Task RegisterAsync(RegisterDTO model) { var resonse = await _httpClient.PostAsJsonAsync($"{BASE_URL}/register", model); var result = await resonse.Content.ReadFromJsonAsync(); return result; } public async Task GetWeatherForecastsAync() { if (string.IsNullOrWhiteSpace(Constants.JWTToken)) return null; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants.JWTToken); return await _httpClient.GetFromJsonAsync($"{BASE_URL}/weather"); } } }