enchance: cambio nombres de variables para ser mas descriptivos

This commit is contained in:
javiermengual 2025-12-30 19:14:59 +01:00
parent 198fccd5bc
commit 1a752c007f
1 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ public class DolibarrApiClient
// ===== FACTURAS ===== // ===== FACTURAS =====
public async Task<InvoiceDetailDto> GetInvoiceAsync(int id) public async Task<InvoiceDetailDto> GetInvoiceAsync(int id)
{ {
var data = await GetAsync<InvoiceDetailResponse>($"invoices/{id}"); var data = await GetResourceAsync<InvoiceDetailResponse>($"invoices/{id}");
return InvoiceMapper.MapToInvoiceDetailDto(data); return InvoiceMapper.MapToInvoiceDetailDto(data);
} }
@ -37,31 +37,31 @@ public class DolibarrApiClient
endpoint += $"&status={status}"; endpoint += $"&status={status}";
} }
var dataList = await GetListAsync<InvoiceResponse>(endpoint); var dataList = await GetCollectionAsync<InvoiceResponse>(endpoint);
return dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList(); return dataList.Select(InvoiceMapper.MapToInvoiceDto).ToList();
} }
// ===== MÉTODOS GENÉRICOS ===== // ===== MÉTODOS GENÉRICOS =====
private async Task<T> GetAsync<T>(string endpoint) where T : class private async Task<T> GetResourceAsync<T>(string endpoint) where T : class
{ {
var response = await _httpClient.GetAsync(endpoint); var response = await _httpClient.GetAsync(endpoint);
await HandleErrorsAsync(response, endpoint); await EnsureSuccessOrThrowAsync(response, endpoint);
return await response.Content.ReadFromJsonAsync<T>() return await response.Content.ReadFromJsonAsync<T>()
?? throw new ApiException($"Failed to deserialize response from Dolibarr for endpoint '{endpoint}'"); ?? throw new ApiException($"Failed to deserialize response from Dolibarr for endpoint '{endpoint}'");
} }
private async Task<List<T>> GetListAsync<T>(string endpoint) where T : class private async Task<List<T>> GetCollectionAsync<T>(string endpoint) where T : class
{ {
var response = await _httpClient.GetAsync(endpoint); var response = await _httpClient.GetAsync(endpoint);
await HandleErrorsAsync(response, endpoint); await EnsureSuccessOrThrowAsync(response, endpoint);
return await response.Content.ReadFromJsonAsync<List<T>>() return await response.Content.ReadFromJsonAsync<List<T>>()
?? throw new ApiException( ?? throw new ApiException(
$"Failed to deserialize list response from Dolibarr for endpoint '{endpoint}'"); $"Failed to deserialize list response from Dolibarr for endpoint '{endpoint}'");
} }
private async Task HandleErrorsAsync(HttpResponseMessage response, string endpoint) private async Task EnsureSuccessOrThrowAsync(HttpResponseMessage response, string endpoint)
{ {
if (response.IsSuccessStatusCode) return; if (response.IsSuccessStatusCode) return;