160afb7c7e
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s
**Blockers Fixed:** 1. InquiryBrowserClient URL hardcoding - Removed: \"http://localhost:5001\" hardcoded in each method - Added: Configured BaseAddress in Program.cs - Now uses: Relative paths (\"inquiry\", \"inquiry/{id}\", etc) - HttpClientFactory pipeline includes TokenRefreshHandler 2. Missing API endpoints in InquiryController - Added: PUT /api/inquiry/{id}/memo - Added: POST /api/inquiry/{id}/convert-to-client - Request DTOs: UpdateAdminMemoRequest, ConvertToClientRequest - ClientService injected (for client creation) **Implementation:** - InquiryBrowserClient: Extended interface * UpdateAdminMemoAsync(id, memo) * ConvertToClientAsync(id, name, phone, serviceType) * All methods use relative paths - InquiryBrowserClient.ConvertToClientResponse * Deserialize API response to extract clientId - InquiryDetail.razor: Full refactor * Before: @inject InquiryService, ClientService (direct service calls) * After: @inject IInquiryBrowserClient (API-only) * OnInitializedAsync: InquiryClient.GetByIdAsync * OnStatusChanged: InquiryClient.UpdateStatusAsync * SaveMemo: InquiryClient.UpdateAdminMemoAsync * ConvertToClient: InquiryClient.ConvertToClientAsync **InquiryList.razor status:** * Also still injects IInquiryRepository (line 4) * Consider refactoring to use IInquiryBrowserClient for consistency **Phase 7 Status:** - ✅ Blog page: Already API-First (ApiClient) - ✅ Inquiry page: Fully API-First (IInquiryBrowserClient) * InquiryTable: ✅ Migrated * InquiryDetail: ✅ Migrated * InquiryList: ⏳ Still uses IInquiryRepository (minor - reads only) **SOLID Applied:** ✓ S: InquiryBrowserClient single responsibility ✓ D: Blazor → IInquiryBrowserClient (not ServiceLayer) ✓ O: Client can change without Blazor impact Next: Check FAQ, Client, TaxFiling pages for same pattern. If all still injecting services directly, migrate sequentially. Then: Phase 6 (SignalR) will have all pages ready. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
143 lines
4.5 KiB
C#
143 lines
4.5 KiB
C#
namespace TaxBaik.Web.Services;
|
|
|
|
using System.Net.Http.Json;
|
|
using TaxBaik.Domain.Entities;
|
|
|
|
/// <summary>
|
|
/// Inquiry API Client for Admin Blazor
|
|
/// SOLID: Single Responsibility - Inquiry API calls only
|
|
/// Dependency Inversion - abstraction via interface
|
|
/// </summary>
|
|
public interface IInquiryBrowserClient
|
|
{
|
|
Task<(IEnumerable<Inquiry> Items, int Total)> GetPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
|
|
Task<Inquiry?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
Task<bool> UpdateStatusAsync(int id, string status, CancellationToken ct = default);
|
|
Task<bool> UpdateAdminMemoAsync(int id, string adminMemo, CancellationToken ct = default);
|
|
Task<int> ConvertToClientAsync(int id, string name, string phone, string serviceType, CancellationToken ct = default);
|
|
}
|
|
|
|
public class InquiryBrowserClient : IInquiryBrowserClient
|
|
{
|
|
private readonly HttpClient _http;
|
|
private readonly ILogger<InquiryBrowserClient> _logger;
|
|
|
|
public InquiryBrowserClient(HttpClient http, ILogger<InquiryBrowserClient> logger)
|
|
{
|
|
_http = http;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<(IEnumerable<Inquiry> Items, int Total)> GetPagedAsync(
|
|
int page = 1, int pageSize = 20, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var result = await _http.GetFromJsonAsync<InquiryPagedResponse>(
|
|
$"inquiry?page={page}&pageSize={pageSize}",
|
|
cancellationToken: ct);
|
|
|
|
return result != null
|
|
? (result.Data, result.Total)
|
|
: ([], 0);
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to fetch inquiries");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<Inquiry?> GetByIdAsync(int id, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
return await _http.GetFromJsonAsync<Inquiry>(
|
|
$"inquiry/{id}",
|
|
cancellationToken: ct);
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to fetch inquiry {InquiryId}", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<bool> UpdateStatusAsync(int id, string status, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var request = new { status };
|
|
var response = await _http.PutAsJsonAsync(
|
|
$"inquiry/{id}/status",
|
|
request,
|
|
cancellationToken: ct);
|
|
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to update inquiry {InquiryId} status", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<bool> UpdateAdminMemoAsync(int id, string adminMemo, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var request = new { adminMemo };
|
|
var response = await _http.PutAsJsonAsync(
|
|
$"inquiry/{id}/memo",
|
|
request,
|
|
cancellationToken: ct);
|
|
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to update inquiry {InquiryId} memo", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<int> ConvertToClientAsync(int id, string name, string phone, string serviceType, CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
var response = await _http.PostAsJsonAsync(
|
|
$"inquiry/{id}/convert-to-client",
|
|
new { name, phone, serviceType },
|
|
cancellationToken: ct);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return 0;
|
|
|
|
var content = await response.Content.ReadAsStringAsync(ct);
|
|
var result = System.Text.Json.JsonSerializer.Deserialize<ConvertToClientResponse>(
|
|
content,
|
|
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
|
|
|
return result?.ClientId ?? 0;
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
_logger.LogError(ex, "Failed to convert inquiry {InquiryId} to client", id);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private class InquiryPagedResponse
|
|
{
|
|
public List<Inquiry> Data { get; set; } = [];
|
|
public int Total { get; set; }
|
|
public int Page { get; set; }
|
|
public int PageSize { get; set; }
|
|
}
|
|
|
|
private class ConvertToClientResponse
|
|
{
|
|
public int ClientId { get; set; }
|
|
}
|
|
}
|