diff --git a/TaxBaik.Web/Components/Admin/InquiryTable.razor b/TaxBaik.Web/Components/Admin/InquiryTable.razor index a98f9d0..a5aed76 100644 --- a/TaxBaik.Web/Components/Admin/InquiryTable.razor +++ b/TaxBaik.Web/Components/Admin/InquiryTable.razor @@ -1,5 +1,5 @@ -@using TaxBaik.Application.Services -@inject InquiryService InquiryService +@using TaxBaik.Web.Services +@inject IInquiryBrowserClient InquiryClient @@ -45,7 +45,7 @@ protected override async Task OnInitializedAsync() { - var (items, _) = await InquiryService.GetPagedAsync(1, 100); + var (items, _) = await InquiryClient.GetPagedAsync(1, 100); inquiries = items.ToList(); FilterInquiries(); } @@ -69,18 +69,14 @@ private static Color GetStatusColor(string status) => status switch { "new" => Color.Warning, - "contacted" => Color.Info, - "completed" => Color.Success, + "consulting" => Color.Info, + "contracted" => Color.Success, + "rejected" => Color.Error, + "closed" => Color.Dark, _ => Color.Default }; - private static string GetStatusLabel(string status) => status switch - { - "new" => "신규", - "contacted" => "연락함", - "completed" => "완료", - _ => status - }; + private static string GetStatusLabel(string status) => InquiryStatusMapper.Labels.GetValueOrDefault(status, status); protected override async Task OnParametersSetAsync() { diff --git a/TaxBaik.Web/Program.cs b/TaxBaik.Web/Program.cs index 0e65b6c..0007730 100644 --- a/TaxBaik.Web/Program.cs +++ b/TaxBaik.Web/Program.cs @@ -75,6 +75,8 @@ builder.Services.AddHttpClient(clie client.BaseAddress = new Uri("http://localhost:5001/taxbaik/api/"); }) .AddHttpMessageHandler(); +builder.Services.AddHttpClient() + .AddHttpMessageHandler(); // UI & 캐시 builder.Services.AddMudServices(); diff --git a/TaxBaik.Web/Services/InquiryBrowserClient.cs b/TaxBaik.Web/Services/InquiryBrowserClient.cs new file mode 100644 index 0000000..b5553bf --- /dev/null +++ b/TaxBaik.Web/Services/InquiryBrowserClient.cs @@ -0,0 +1,90 @@ +namespace TaxBaik.Web.Services; + +using System.Net.Http.Json; +using TaxBaik.Domain.Entities; + +/// +/// Inquiry API Client for Admin Blazor +/// SOLID: Single Responsibility - Inquiry API calls only +/// Dependency Inversion - abstraction via interface +/// +public interface IInquiryBrowserClient +{ + Task<(IEnumerable Items, int Total)> GetPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default); + Task GetByIdAsync(int id, CancellationToken ct = default); + Task UpdateStatusAsync(int id, string status, CancellationToken ct = default); +} + +public class InquiryBrowserClient : IInquiryBrowserClient +{ + private readonly HttpClient _http; + private readonly ILogger _logger; + + public InquiryBrowserClient(HttpClient http, ILogger logger) + { + _http = http; + _logger = logger; + } + + public async Task<(IEnumerable Items, int Total)> GetPagedAsync( + int page = 1, int pageSize = 20, CancellationToken ct = default) + { + try + { + var result = await _http.GetFromJsonAsync( + $"http://localhost:5001/taxbaik/api/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 GetByIdAsync(int id, CancellationToken ct = default) + { + try + { + return await _http.GetFromJsonAsync( + $"http://localhost:5001/taxbaik/api/inquiry/{id}", + cancellationToken: ct); + } + catch (HttpRequestException ex) + { + _logger.LogError(ex, "Failed to fetch inquiry {InquiryId}", id); + throw; + } + } + + public async Task UpdateStatusAsync(int id, string status, CancellationToken ct = default) + { + try + { + var request = new { status }; + var response = await _http.PutAsJsonAsync( + $"http://localhost:5001/taxbaik/api/inquiry/{id}/status", + request, + cancellationToken: ct); + + return response.IsSuccessStatusCode; + } + catch (HttpRequestException ex) + { + _logger.LogError(ex, "Failed to update inquiry {InquiryId} status", id); + throw; + } + } + + private class InquiryPagedResponse + { + public List Data { get; set; } = []; + public int Total { get; set; } + public int Page { get; set; } + public int PageSize { get; set; } + } +}