Introduce interfaces for all API clients and update dependency injection to use these interfaces. Refactor services and components to depend on abstractions instead of concrete implementations, improving testability and maintainability.
22 lines
592 B
C#
22 lines
592 B
C#
using System.Net.Http.Json;
|
|
using DbFirst.BlazorWebApp.Models;
|
|
|
|
namespace DbFirst.BlazorWebApp.Services;
|
|
|
|
public class DashboardApiClient : IDashboardApiClient
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private const string Endpoint = "api/dashboard/dashboards";
|
|
|
|
public DashboardApiClient(HttpClient httpClient)
|
|
{
|
|
_httpClient = httpClient;
|
|
}
|
|
|
|
public async Task<List<DashboardInfoDto>> GetAllAsync()
|
|
{
|
|
var result = await _httpClient.GetFromJsonAsync<List<DashboardInfoDto>>(Endpoint);
|
|
return result ?? new List<DashboardInfoDto>();
|
|
}
|
|
}
|