fbdbbc7a1f
TaxBaik CI/CD / build-and-deploy (push) Successful in 54s
**Clients Migration Complete:** - ClientController: GET /api/client (paged), POST/PUT/DELETE - ClientBrowserClient: IClientBrowserClient interface + implementation - ClientList.razor: Service → API client - ClientEdit.razor: Service → API client (Create/Update) **TaxFilings API Framework Ready:** - TaxFilingController: GET upcoming, GET by client, POST/PUT/DELETE - TaxFilingBrowserClient: ITaxFilingBrowserClient interface + impl - Registered in Program.cs with TokenRefreshHandler **SOLID Applied:** ✓ Separation of concerns (Controller → Service → Repository) ✓ Dependency inversion (Blazor → Browser clients, not services) ✓ Interface segregation (Specialized clients per domain) **Status:** - Clients Blazor: ✅ ClientList + ClientEdit refactored - TaxFilings Blazor: ⏳ Pending refactor (pages exist) - Faqs: ⏳ API + Blazor pending - Announcements: ⏳ API + Blazor pending - Phase 6 SignalR: ⏳ Deferred Next: Refactor TaxFilings Blazor pages, then Faqs & Announcements Build: ✅ Success (0 errors, 2 warnings in Dashboard) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
133 lines
4.4 KiB
C#
133 lines
4.4 KiB
C#
namespace TaxBaik.Web.Services;
|
|
|
|
using System.Net.Http.Json;
|
|
using TaxBaik.Domain.Entities;
|
|
|
|
/// <summary>
|
|
/// TaxFiling API Client for Admin Blazor
|
|
/// </summary>
|
|
public interface ITaxFilingBrowserClient
|
|
{
|
|
Task<IEnumerable<TaxFiling>> GetUpcomingAsync(int daysAhead = 30, CancellationToken ct = default);
|
|
Task<IEnumerable<TaxFiling>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
|
Task<TaxFiling?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
Task<TaxFiling?> CreateAsync(TaxFiling filing, CancellationToken ct = default);
|
|
Task<TaxFiling?> UpdateAsync(int id, TaxFiling filing, CancellationToken ct = default);
|
|
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
|
}
|
|
|
|
public class TaxFilingBrowserClient : ITaxFilingBrowserClient
|
|
{
|
|
private readonly HttpClient _http;
|
|
private readonly ILogger<TaxFilingBrowserClient> _logger;
|
|
|
|
public TaxFilingBrowserClient(HttpClient http, ILogger<TaxFilingBrowserClient> logger)
|
|
{
|
|
_http = http;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<IEnumerable<TaxFiling>> GetUpcomingAsync(int daysAhead = 30, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var result = await _http.GetFromJsonAsync<TaxFilingListResponse>(
|
|
$"tax-filing/upcoming?daysAhead={daysAhead}", cancellationToken: ct);
|
|
return result?.Data ?? [];
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to fetch upcoming filings");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<TaxFiling>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var result = await _http.GetFromJsonAsync<TaxFilingListResponse>(
|
|
$"tax-filing/client/{clientId}", cancellationToken: ct);
|
|
return result?.Data ?? [];
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to fetch filings for client {ClientId}", clientId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<TaxFiling?> GetByIdAsync(int id, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
return await _http.GetFromJsonAsync<TaxFiling>(
|
|
$"tax-filing/{id}", cancellationToken: ct);
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to fetch filing {FilingId}", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<TaxFiling?> CreateAsync(TaxFiling filing, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var response = await _http.PostAsJsonAsync("tax-filing", filing, cancellationToken: ct);
|
|
if (!response.IsSuccessStatusCode)
|
|
return null;
|
|
|
|
var content = await response.Content.ReadAsStringAsync(ct);
|
|
return System.Text.Json.JsonSerializer.Deserialize<TaxFiling>(
|
|
content,
|
|
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to create filing");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<TaxFiling?> UpdateAsync(int id, TaxFiling filing, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var response = await _http.PutAsJsonAsync($"tax-filing/{id}", filing, cancellationToken: ct);
|
|
if (!response.IsSuccessStatusCode)
|
|
return null;
|
|
|
|
var content = await response.Content.ReadAsStringAsync(ct);
|
|
return System.Text.Json.JsonSerializer.Deserialize<TaxFiling>(
|
|
content,
|
|
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to update filing {FilingId}", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var response = await _http.DeleteAsync($"tax-filing/{id}", cancellationToken: ct);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to delete filing {FilingId}", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private class TaxFilingListResponse
|
|
{
|
|
public List<TaxFiling> Data { get; set; } = [];
|
|
}
|
|
}
|