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; } } }