diff --git a/TaxBaik.Web/Program.cs b/TaxBaik.Web/Program.cs index 64c20cc..9fe1141 100644 --- a/TaxBaik.Web/Program.cs +++ b/TaxBaik.Web/Program.cs @@ -246,32 +246,27 @@ builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(apiBaseUrl); -}) - .AddHttpMessageHandler(); +}); builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(apiBaseUrl); -}) - .AddHttpMessageHandler(); +}); builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(apiBaseUrl); -}) - .AddHttpMessageHandler(); +}); builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(apiBaseUrl); -}) - .AddHttpMessageHandler(); +}); builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(apiBaseUrl); -}) - .AddHttpMessageHandler(); +}); // UI & 캐시 (MudBlazor Theme Customization) builder.Services.AddMudServices(config => diff --git a/TaxBaik.Web/Services/AdminClients/IConsultingActivityBrowserClient.cs b/TaxBaik.Web/Services/AdminClients/IConsultingActivityBrowserClient.cs index 5096236..503d53b 100644 --- a/TaxBaik.Web/Services/AdminClients/IConsultingActivityBrowserClient.cs +++ b/TaxBaik.Web/Services/AdminClients/IConsultingActivityBrowserClient.cs @@ -14,15 +14,24 @@ public interface IConsultingActivityBrowserClient Task DeleteAsync(int id, CancellationToken ct = default); } -public class ConsultingActivityBrowserClient(HttpClient httpClient, ILogger logger) +public class ConsultingActivityBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger logger) : IConsultingActivityBrowserClient { private const string BaseUrl = "/api/consultingactivity"; + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(tokenStore.AccessToken)) + httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken); + else + httpClient.DefaultRequestHeaders.Authorization = null; + } + public async Task> GetAllAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); return await httpClient.GetFromJsonAsync>($"{BaseUrl}", ct) ?? []; } catch (Exception ex) @@ -36,6 +45,7 @@ public class ConsultingActivityBrowserClient(HttpClient httpClient, ILogger>($"{BaseUrl}/client/{clientId}", ct) ?? []; } catch (Exception ex) @@ -49,6 +59,7 @@ public class ConsultingActivityBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/pending-followups", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -66,6 +77,7 @@ public class ConsultingActivityBrowserClient(HttpClient httpClient, ILogger logger) +public class ContractBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger logger) : IContractBrowserClient { private const string BaseUrl = "/api/contract"; + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(tokenStore.AccessToken)) + httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken); + else + httpClient.DefaultRequestHeaders.Authorization = null; + } + public async Task> GetAllAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); return await httpClient.GetFromJsonAsync>($"{BaseUrl}", ct) ?? []; } catch (Exception ex) @@ -38,6 +47,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/{id}", ct); } catch (Exception ex) @@ -51,6 +61,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger>($"{BaseUrl}/client/{clientId}", ct) ?? []; } catch (Exception ex) @@ -64,6 +75,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/active", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -80,6 +92,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/expiring?daysAhead={daysAhead}", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -96,6 +109,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/mrr", ct); if (response.TryGetProperty("mrr", out var mrrValue)) return System.Text.Json.JsonSerializer.Deserialize(mrrValue.GetRawText()); @@ -113,6 +127,7 @@ public class ContractBrowserClient(HttpClient httpClient, ILogger logger) +public class RevenueTrackingBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger logger) : IRevenueTrackingBrowserClient { private const string BaseUrl = "/api/revenuetracking"; + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(tokenStore.AccessToken)) + httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken); + else + httpClient.DefaultRequestHeaders.Authorization = null; + } + public async Task> GetAllAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); return await httpClient.GetFromJsonAsync>($"{BaseUrl}", ct) ?? []; } catch (Exception ex) @@ -38,6 +47,7 @@ public class RevenueTrackingBrowserClient(HttpClient httpClient, ILogger>($"{BaseUrl}/client/{clientId}", ct) ?? []; } catch (Exception ex) @@ -51,6 +61,7 @@ public class RevenueTrackingBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/pending", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -67,6 +78,7 @@ public class RevenueTrackingBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/monthly?year={year}&month={month}", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -83,6 +95,7 @@ public class RevenueTrackingBrowserClient(HttpClient httpClient, ILogger( $"{BaseUrl}/total?startDate={startDate:yyyy-MM-dd}&endDate={endDate:yyyy-MM-dd}", ct); if (response.TryGetProperty("total", out var totalValue)) @@ -101,6 +114,7 @@ public class RevenueTrackingBrowserClient(HttpClient httpClient, ILogger logger) +public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger logger) : ITaxFilingScheduleBrowserClient { private const string BaseUrl = "/api/taxfilingschedule"; + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(tokenStore.AccessToken)) + httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken); + else + httpClient.DefaultRequestHeaders.Authorization = null; + } + public async Task> GetAllAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); return await httpClient.GetFromJsonAsync>($"{BaseUrl}", ct) ?? []; } catch (Exception ex) @@ -37,6 +46,7 @@ public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/{id}", ct); } catch (Exception ex) @@ -50,6 +60,7 @@ public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ILogger>($"{BaseUrl}/client/{clientId}", ct) ?? []; } catch (Exception ex) @@ -63,6 +74,7 @@ public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/upcoming?daysAhead={daysAhead}", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -80,6 +92,7 @@ public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ILogger logger) : ITaxProfileBrowserClient +public class TaxProfileBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger logger) : ITaxProfileBrowserClient { private const string BaseUrl = "/api/taxprofile"; + private void EnsureAuthHeader() + { + if (!string.IsNullOrEmpty(tokenStore.AccessToken)) + httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken); + else + httpClient.DefaultRequestHeaders.Authorization = null; + } + public async Task> GetAllAsync(CancellationToken ct = default) { try { + EnsureAuthHeader(); return await httpClient.GetFromJsonAsync>($"{BaseUrl}", ct) ?? []; } catch (Exception ex) @@ -38,6 +47,7 @@ public class TaxProfileBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/{id}", ct); } catch (Exception ex) @@ -51,6 +61,7 @@ public class TaxProfileBrowserClient(HttpClient httpClient, ILogger>($"{BaseUrl}/client/{clientId}", ct) ?? []; } catch (Exception ex) @@ -64,6 +75,7 @@ public class TaxProfileBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/high-risk", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -80,6 +92,7 @@ public class TaxProfileBrowserClient(HttpClient httpClient, ILogger($"{BaseUrl}/upcoming-filings?daysAhead={daysAhead}", ct); if (response.TryGetProperty("data", out var data)) return System.Text.Json.JsonSerializer.Deserialize>(data.GetRawText()) ?? []; @@ -97,6 +110,7 @@ public class TaxProfileBrowserClient(HttpClient httpClient, ILogger GetSummaryAsync(CancellationToken ct = default)