Fix Solicitud de Token 2
This commit is contained in:
		| @@ -29,7 +29,7 @@ public class ElectoralApiService : IElectoralApiService | |||||||
|         _rateLimiter = rateLimiter; |         _rateLimiter = rateLimiter; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public async Task<string?> GetAuthTokenAsync() |     public async Task<TokenResponse?> GetAuthTokenAsync() | ||||||
|     { |     { | ||||||
|         // "Pedir una ficha". Este método ahora devuelve un "lease" (permiso). |         // "Pedir una ficha". Este método ahora devuelve un "lease" (permiso). | ||||||
|         // Si no hay fichas, esperará aquí automáticamente hasta que se rellene el cubo. |         // Si no hay fichas, esperará aquí automáticamente hasta que se rellene el cubo. | ||||||
| @@ -42,14 +42,18 @@ public class ElectoralApiService : IElectoralApiService | |||||||
|             var username = _configuration["ElectoralApi:Username"]; |             var username = _configuration["ElectoralApi:Username"]; | ||||||
|             var password = _configuration["ElectoralApi:Password"]; |             var password = _configuration["ElectoralApi:Password"]; | ||||||
|             if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null; |             if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null; | ||||||
|             var request = new HttpRequestMessage(HttpMethod.Get, "/api/createtoken/"); |  | ||||||
|  |             var request = new HttpRequestMessage(HttpMethod.Get, "/api/createtoken"); | ||||||
|             request.Headers.Add("username", username); |             request.Headers.Add("username", username); | ||||||
|             request.Headers.Add("password", password); |             request.Headers.Add("password", password); | ||||||
|  |  | ||||||
|             var response = await client.SendAsync(request); |             var response = await client.SendAsync(request); | ||||||
|             if (!response.IsSuccessStatusCode) return null; |             if (!response.IsSuccessStatusCode) return null; | ||||||
|             var tokenResponse = await response.Content.ReadFromJsonAsync<TokenResponse>(); |  | ||||||
|             return (tokenResponse is { Success: true, Data.AccessToken: not null }) ? tokenResponse.Data.AccessToken : null; |             // Ahora esto es válido, porque el método devuelve Task<TokenResponse?> | ||||||
|  |             return await response.Content.ReadFromJsonAsync<TokenResponse>(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Si no se pudo obtener un permiso (ej. la cola está llena), devolvemos null. |         // Si no se pudo obtener un permiso (ej. la cola está llena), devolvemos null. | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -7,8 +7,7 @@ namespace Elecciones.Infrastructure.Services; | |||||||
|  |  | ||||||
| public interface IElectoralApiService | public interface IElectoralApiService | ||||||
| { | { | ||||||
|     Task<string?> GetAuthTokenAsync(); |     Task<TokenResponse?> GetAuthTokenAsync(); | ||||||
|  |  | ||||||
|     // Métodos para catálogos |     // Métodos para catálogos | ||||||
|     Task<CatalogoDto?> GetCatalogoAmbitosAsync(string authToken, int categoriaId); |     Task<CatalogoDto?> GetCatalogoAmbitosAsync(string authToken, int categoriaId); | ||||||
|     Task<List<AgrupacionDto>?> GetAgrupacionesAsync(string authToken, string distritoId, int categoriaId); |     Task<List<AgrupacionDto>?> GetAgrupacionesAsync(string authToken, string distritoId, int categoriaId); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user