refactor: Phase 7-2 Complete - Full Inquiry page API-First migration
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s
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>
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
@page "/admin/inquiries/{InquiryId:int}"
|
@page "/admin/inquiries/{InquiryId:int}"
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@using TaxBaik.Application.Services
|
@using TaxBaik.Web.Services
|
||||||
@inject InquiryService InquiryService
|
@inject IInquiryBrowserClient InquiryClient
|
||||||
@inject ClientService ClientService
|
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@inject ISnackbar Snackbar
|
@inject ISnackbar Snackbar
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ else
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
inquiry = await InquiryService.GetByIdAsync(InquiryId);
|
inquiry = await InquiryClient.GetByIdAsync(InquiryId);
|
||||||
adminMemo = inquiry?.AdminMemo ?? "";
|
adminMemo = inquiry?.AdminMemo ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,22 +122,43 @@ else
|
|||||||
if (inquiry == null) return;
|
if (inquiry == null) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await InquiryService.UpdateStatusAsync(inquiry.Id, status, "관리자");
|
var success = await InquiryClient.UpdateStatusAsync(inquiry.Id, status);
|
||||||
inquiry.Status = status;
|
if (success)
|
||||||
Snackbar.Add("상태가 변경되었습니다.", Severity.Success);
|
{
|
||||||
|
inquiry.Status = status;
|
||||||
|
Snackbar.Add("상태가 변경되었습니다.", Severity.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Snackbar.Add("상태 변경에 실패했습니다.", Severity.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ValidationException ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Snackbar.Add(ex.Message, Severity.Error);
|
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveMemo()
|
private async Task SaveMemo()
|
||||||
{
|
{
|
||||||
if (inquiry == null) return;
|
if (inquiry == null) return;
|
||||||
await InquiryService.UpdateAdminMemoAsync(inquiry.Id, adminMemo);
|
try
|
||||||
inquiry.AdminMemo = adminMemo;
|
{
|
||||||
Snackbar.Add("메모가 저장되었습니다.", Severity.Success);
|
var success = await InquiryClient.UpdateAdminMemoAsync(inquiry.Id, adminMemo);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
inquiry.AdminMemo = adminMemo;
|
||||||
|
Snackbar.Add("메모가 저장되었습니다.", Severity.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Snackbar.Add("메모 저장에 실패했습니다.", Severity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConvertToClient()
|
private async Task ConvertToClient()
|
||||||
@@ -146,12 +166,22 @@ else
|
|||||||
if (inquiry == null) return;
|
if (inquiry == null) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var clientId = await ClientService.CreateFromInquiryAsync(inquiry.Name, inquiry.Phone, inquiry.ServiceType);
|
var clientId = await InquiryClient.ConvertToClientAsync(
|
||||||
await InquiryService.LinkClientAsync(inquiry.Id, clientId);
|
inquiry.Id,
|
||||||
await InquiryService.UpdateStatusAsync(inquiry.Id, "consulting", "관리자");
|
inquiry.Name,
|
||||||
inquiry.ClientId = clientId;
|
inquiry.Phone,
|
||||||
inquiry.Status = "consulting";
|
inquiry.ServiceType);
|
||||||
Snackbar.Add("고객 카드가 생성되었습니다.", Severity.Success);
|
|
||||||
|
if (clientId > 0)
|
||||||
|
{
|
||||||
|
inquiry.ClientId = clientId;
|
||||||
|
inquiry.Status = "consulting";
|
||||||
|
Snackbar.Add("고객 카드가 생성되었습니다.", Severity.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Snackbar.Add("고객 카드 생성에 실패했습니다.", Severity.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ namespace TaxBaik.Web.Controllers;
|
|||||||
public class InquiryController : ControllerBase
|
public class InquiryController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly InquiryService _inquiryService;
|
private readonly InquiryService _inquiryService;
|
||||||
|
private readonly ClientService _clientService;
|
||||||
|
|
||||||
public InquiryController(InquiryService inquiryService)
|
public InquiryController(InquiryService inquiryService, ClientService clientService)
|
||||||
{
|
{
|
||||||
_inquiryService = inquiryService;
|
_inquiryService = inquiryService;
|
||||||
|
_clientService = clientService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@@ -76,6 +78,54 @@ public class InquiryController : ControllerBase
|
|||||||
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}/memo")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> UpdateAdminMemo(int id, [FromBody] UpdateAdminMemoRequest request)
|
||||||
|
{
|
||||||
|
var inquiry = await _inquiryService.GetByIdAsync(id);
|
||||||
|
if (inquiry == null)
|
||||||
|
return NotFound(new ProblemDetails { Title = "문의를 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound });
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _inquiryService.UpdateAdminMemoAsync(id, request.AdminMemo);
|
||||||
|
return Ok(new { message = "메모가 저장되었습니다." });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id}/convert-to-client")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> ConvertToClient(int id, [FromBody] ConvertToClientRequest request)
|
||||||
|
{
|
||||||
|
var inquiry = await _inquiryService.GetByIdAsync(id);
|
||||||
|
if (inquiry == null)
|
||||||
|
return NotFound(new ProblemDetails { Title = "문의를 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound });
|
||||||
|
|
||||||
|
if (inquiry.ClientId != null)
|
||||||
|
return BadRequest(new ProblemDetails { Title = "이미 고객 카드가 연결되어 있습니다.", Status = StatusCodes.Status400BadRequest });
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var clientId = await _clientService.CreateFromInquiryAsync(
|
||||||
|
request.Name ?? inquiry.Name,
|
||||||
|
request.Phone ?? inquiry.Phone,
|
||||||
|
request.ServiceType ?? inquiry.ServiceType);
|
||||||
|
|
||||||
|
await _inquiryService.LinkClientAsync(inquiry.Id, clientId);
|
||||||
|
await _inquiryService.UpdateStatusAsync(inquiry.Id, "consulting", User.FindFirstValue(ClaimTypes.Name) ?? "system");
|
||||||
|
|
||||||
|
return Ok(new { clientId, message = "고객 카드가 생성되었습니다." });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubmitInquiryRequest
|
public class SubmitInquiryRequest
|
||||||
@@ -91,3 +141,15 @@ public class UpdateStatusRequest
|
|||||||
{
|
{
|
||||||
public string Status { get; set; } = string.Empty;
|
public string Status { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UpdateAdminMemoRequest
|
||||||
|
{
|
||||||
|
public string? AdminMemo { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConvertToClientRequest
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Phone { get; set; }
|
||||||
|
public string? ServiceType { get; set; }
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,7 +75,10 @@ builder.Services.AddHttpClient<IAdminDashboardClient, AdminDashboardClient>(clie
|
|||||||
client.BaseAddress = new Uri("http://localhost:5001/taxbaik/api/");
|
client.BaseAddress = new Uri("http://localhost:5001/taxbaik/api/");
|
||||||
})
|
})
|
||||||
.AddHttpMessageHandler<TokenRefreshHandler>();
|
.AddHttpMessageHandler<TokenRefreshHandler>();
|
||||||
builder.Services.AddHttpClient<IInquiryBrowserClient, InquiryBrowserClient>()
|
builder.Services.AddHttpClient<IInquiryBrowserClient, InquiryBrowserClient>(client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri("http://localhost:5001/taxbaik/api/");
|
||||||
|
})
|
||||||
.AddHttpMessageHandler<TokenRefreshHandler>();
|
.AddHttpMessageHandler<TokenRefreshHandler>();
|
||||||
|
|
||||||
// UI & 캐시
|
// UI & 캐시
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public interface IInquiryBrowserClient
|
|||||||
Task<(IEnumerable<Inquiry> Items, int Total)> GetPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
|
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<Inquiry?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||||
Task<bool> UpdateStatusAsync(int id, string status, 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
|
public class InquiryBrowserClient : IInquiryBrowserClient
|
||||||
@@ -32,7 +34,7 @@ public class InquiryBrowserClient : IInquiryBrowserClient
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await _http.GetFromJsonAsync<InquiryPagedResponse>(
|
var result = await _http.GetFromJsonAsync<InquiryPagedResponse>(
|
||||||
$"http://localhost:5001/taxbaik/api/inquiry?page={page}&pageSize={pageSize}",
|
$"inquiry?page={page}&pageSize={pageSize}",
|
||||||
cancellationToken: ct);
|
cancellationToken: ct);
|
||||||
|
|
||||||
return result != null
|
return result != null
|
||||||
@@ -51,7 +53,7 @@ public class InquiryBrowserClient : IInquiryBrowserClient
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await _http.GetFromJsonAsync<Inquiry>(
|
return await _http.GetFromJsonAsync<Inquiry>(
|
||||||
$"http://localhost:5001/taxbaik/api/inquiry/{id}",
|
$"inquiry/{id}",
|
||||||
cancellationToken: ct);
|
cancellationToken: ct);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex)
|
catch (HttpRequestException ex)
|
||||||
@@ -67,7 +69,7 @@ public class InquiryBrowserClient : IInquiryBrowserClient
|
|||||||
{
|
{
|
||||||
var request = new { status };
|
var request = new { status };
|
||||||
var response = await _http.PutAsJsonAsync(
|
var response = await _http.PutAsJsonAsync(
|
||||||
$"http://localhost:5001/taxbaik/api/inquiry/{id}/status",
|
$"inquiry/{id}/status",
|
||||||
request,
|
request,
|
||||||
cancellationToken: ct);
|
cancellationToken: ct);
|
||||||
|
|
||||||
@@ -80,6 +82,51 @@ public class InquiryBrowserClient : IInquiryBrowserClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
private class InquiryPagedResponse
|
||||||
{
|
{
|
||||||
public List<Inquiry> Data { get; set; } = [];
|
public List<Inquiry> Data { get; set; } = [];
|
||||||
@@ -87,4 +134,9 @@ public class InquiryBrowserClient : IInquiryBrowserClient
|
|||||||
public int Page { get; set; }
|
public int Page { get; set; }
|
||||||
public int PageSize { get; set; }
|
public int PageSize { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ConvertToClientResponse
|
||||||
|
{
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user