Files
taxbaik/TaxBaik.Web.Client/Services/CategoryBrowserClient.cs
T
kjh2064 cb47349a25
TaxBaik CI/CD / build-and-deploy (push) Has been cancelled
feat(admin): stabilize blog and admin patterns
2026-07-02 10:46:27 +09:00

36 lines
949 B
C#

namespace TaxBaik.Web.Services;
using System.Net.Http.Json;
using TaxBaik.Domain.Entities;
public interface ICategoryBrowserClient
{
Task<IReadOnlyList<Category>> GetAllAsync(CancellationToken ct = default);
}
public class CategoryBrowserClient : ICategoryBrowserClient
{
private readonly HttpClient _http;
private readonly ILogger<CategoryBrowserClient> _logger;
public CategoryBrowserClient(HttpClient http, ILogger<CategoryBrowserClient> logger)
{
_http = http;
_logger = logger;
}
public async Task<IReadOnlyList<Category>> GetAllAsync(CancellationToken ct = default)
{
try
{
var result = await _http.GetFromJsonAsync<List<Category>>("category", cancellationToken: ct);
return result ?? [];
}
catch (HttpRequestException ex)
{
_logger.LogError(ex, "Failed to fetch categories");
throw;
}
}
}