Fix catalogo y removido el fake de pruebas
This commit is contained in:
@@ -42,10 +42,11 @@ public class ElectoralApiService : IElectoralApiService
|
||||
: null;
|
||||
}
|
||||
|
||||
public async Task<List<CatalogoDto>?> GetCatalogoCompletoAsync(string authToken)
|
||||
public async Task<List<CatalogoDto>?> GetCatalogoAmbitosAsync(string authToken, int categoriaId)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient("ElectoralApiClient");
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/api/catalogo/getCatalogo?categoriald=5");
|
||||
// La URL ahora es dinámica y usa el categoriaId
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, $"/api/catalogo/getCatalogo?categoriald={categoriaId}");
|
||||
request.Headers.Add("Authorization", $"Bearer {authToken}");
|
||||
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
using Elecciones.Core.DTOs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using static Elecciones.Core.DTOs.BancaDto;
|
||||
|
||||
namespace Elecciones.Infrastructure.Services;
|
||||
|
||||
public class FakeElectoralApiService : IElectoralApiService
|
||||
{
|
||||
private readonly ILogger<FakeElectoralApiService> _logger;
|
||||
private List<AmbitoDto>? _fakeAmbitosCache = null;
|
||||
private readonly Random _random = new Random();
|
||||
|
||||
public FakeElectoralApiService(ILogger<FakeElectoralApiService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void GenerateFakeAmbitosFromGeoJson()
|
||||
{
|
||||
if (_fakeAmbitosCache != null) return;
|
||||
_logger.LogWarning("--- USANDO SERVICIO FALSO (FAKE) ---");
|
||||
_logger.LogInformation("Generando datos de prueba de ámbitos desde el archivo GeoJSON...");
|
||||
|
||||
var geoJsonPath = Path.Combine(AppContext.BaseDirectory, "buenos-aires-municipios.geojson");
|
||||
if (!File.Exists(geoJsonPath))
|
||||
{
|
||||
_logger.LogError("No se encontró el archivo buenos-aires-municipios.geojson.");
|
||||
_fakeAmbitosCache = new List<AmbitoDto>();
|
||||
return;
|
||||
}
|
||||
|
||||
var geoJsonString = File.ReadAllText(geoJsonPath);
|
||||
using var document = JsonDocument.Parse(geoJsonString);
|
||||
var features = document.RootElement.GetProperty("features").EnumerateArray().ToList();
|
||||
|
||||
var ambitos = new List<AmbitoDto>();
|
||||
ambitos.Add(new AmbitoDto { NivelId = 10, Nombre = "BUENOS AIRES", CodigoAmbitos = new CodigoAmbitoDto { DistritoId = "02" } });
|
||||
var secciones = new List<AmbitoDto> {
|
||||
new() { NivelId = 4, Nombre = "PRIMERA SECCION ELECTORAL", CodigoAmbitos = new CodigoAmbitoDto { DistritoId = "02", SeccionId = "0001" } },
|
||||
new() { NivelId = 4, Nombre = "SEGUNDA SECCION ELECTORAL", CodigoAmbitos = new CodigoAmbitoDto { DistritoId = "02", SeccionId = "0002" } },
|
||||
new() { NivelId = 4, Nombre = "TERCERA SECCION ELECTORAL", CodigoAmbitos = new CodigoAmbitoDto { DistritoId = "02", SeccionId = "0003" } }
|
||||
};
|
||||
ambitos.AddRange(secciones);
|
||||
|
||||
for (int i = 0; i < features.Count; i++)
|
||||
{
|
||||
var feature = features[i];
|
||||
var properties = feature.GetProperty("properties");
|
||||
var seccionAsignada = secciones[i % secciones.Count];
|
||||
ambitos.Add(new AmbitoDto { NivelId = 5, Nombre = properties.GetProperty("nam").GetString() ?? "Sin Nombre", CodigoAmbitos = new CodigoAmbitoDto { MunicipioId = properties.GetProperty("cca").GetString(), DistritoId = "02", SeccionId = seccionAsignada.CodigoAmbitos.SeccionId } });
|
||||
}
|
||||
_fakeAmbitosCache = ambitos;
|
||||
_logger.LogInformation("Se generaron {count} ámbitos de prueba (Provincia, Secciones y Municipios).", _fakeAmbitosCache.Count);
|
||||
}
|
||||
|
||||
public Task<ResumenDto?> GetResumenAsync(string authToken, string distritoId)
|
||||
{
|
||||
_logger.LogInformation("Simulando obtención de Resumen para distrito {DistritoId}...", distritoId);
|
||||
var resumen = new ResumenDto
|
||||
{
|
||||
ValoresTotalizadosPositivos = new List<ResumenPositivoDto>
|
||||
{
|
||||
new() { IdAgrupacion = "025", Votos = 2500000 + _random.Next(1000), VotosPorcentaje = 45.12m },
|
||||
new() { IdAgrupacion = "018", Votos = 2100000 + _random.Next(1000), VotosPorcentaje = 38.78m },
|
||||
new() { IdAgrupacion = "031", Votos = 800000 + _random.Next(1000), VotosPorcentaje = 14.10m }
|
||||
}
|
||||
};
|
||||
return Task.FromResult<ResumenDto?>(resumen);
|
||||
}
|
||||
|
||||
public Task<EstadoRecuentoGeneralDto?> GetEstadoRecuentoGeneralAsync(string authToken, string distritoId)
|
||||
{
|
||||
_logger.LogInformation("Simulando obtención de Estado de Recuento General para distrito {DistritoId}...", distritoId);
|
||||
var estado = new EstadoRecuentoGeneralDto
|
||||
{
|
||||
MesasEsperadas = 38000,
|
||||
MesasTotalizadas = _random.Next(28000, 37000),
|
||||
MesasTotalizadasPorcentaje = 95.5m,
|
||||
CantidadElectores = 12500000,
|
||||
CantidadVotantes = 9375000,
|
||||
ParticipacionPorcentaje = 75.0m
|
||||
};
|
||||
return Task.FromResult<EstadoRecuentoGeneralDto?>(estado);
|
||||
}
|
||||
|
||||
public Task<string?> GetAuthTokenAsync()
|
||||
{
|
||||
_logger.LogInformation("Simulando obtención de token...");
|
||||
return Task.FromResult<string?>("FAKE_TOKEN_FOR_DEVELOPMENT");
|
||||
}
|
||||
|
||||
public Task<List<CatalogoDto>?> GetCatalogoCompletoAsync(string authToken)
|
||||
{
|
||||
GenerateFakeAmbitosFromGeoJson();
|
||||
var catalogo = new List<CatalogoDto> { new() { Version = 1, CategoriaId = 5, Ambitos = _fakeAmbitosCache ?? new List<AmbitoDto>(), Niveles = new List<NivelDto> { new() { NivelId = 10, Nombre = "Provincia" }, new() { NivelId = 4, Nombre = "Seccion" }, new() { NivelId = 5, Nombre = "Municipio" } } } };
|
||||
return Task.FromResult<List<CatalogoDto>?>(catalogo);
|
||||
}
|
||||
|
||||
public Task<List<AgrupacionDto>?> GetAgrupacionesAsync(string authToken, string distritoId, int categoriaId)
|
||||
{
|
||||
var agrupaciones = new List<AgrupacionDto> { new() { IdAgrupacion = "018", IdAgrupacionTelegrama = "131", NombreAgrupacion = "FRENTE DE AVANZADA" }, new() { IdAgrupacion = "025", IdAgrupacionTelegrama = "132", NombreAgrupacion = "ALIANZA POR EL FUTURO" }, new() { IdAgrupacion = "031", IdAgrupacionTelegrama = "133", NombreAgrupacion = "UNION POPULAR" }, new() { IdAgrupacion = "045", IdAgrupacionTelegrama = "134", NombreAgrupacion = "PARTIDO VECINALISTA" } };
|
||||
return Task.FromResult<List<AgrupacionDto>?>(agrupaciones);
|
||||
}
|
||||
|
||||
public Task<ResultadosDto?> GetResultadosAsync(string authToken, string distritoId, string seccionId, string municipioId)
|
||||
{
|
||||
var resultados = new ResultadosDto { FechaTotalizacion = DateTime.Now.ToString("o"), EstadoRecuento = new EstadoRecuentoDto { MesasEsperadas = _random.Next(100, 2000), MesasTotalizadas = _random.Next(50, 100), CantidadElectores = _random.Next(50000, 600000), ParticipacionPorcentaje = _random.Next(60, 85) + (decimal)_random.NextDouble() }, ValoresTotalizadosPositivos = new List<VotosPositivosDto> { new() { IdAgrupacion = "018", Votos = _random.Next(10000, 20000) }, new() { IdAgrupacion = "025", Votos = _random.Next(15000, 25000) }, new() { IdAgrupacion = "031", Votos = _random.Next(5000, 10000) }, new() { IdAgrupacion = "045", Votos = _random.Next(2000, 5000) } }, ValoresTotalizadosOtros = new VotosOtrosDto { VotosEnBlanco = _random.Next(1000, 2000), VotosNulos = _random.Next(500, 1000), VotosRecurridos = _random.Next(20, 50) } };
|
||||
return Task.FromResult<ResultadosDto?>(resultados);
|
||||
}
|
||||
|
||||
public Task<RepartoBancasDto?> GetBancasAsync(string authToken, string distritoId, string seccionId)
|
||||
{
|
||||
var reparto = new RepartoBancasDto { RepartoBancas = new List<BancaDto> { new() { IdAgrupacion = "025", NroBancas = _random.Next(5, 9) }, new() { IdAgrupacion = "018", NroBancas = _random.Next(3, 7) } } };
|
||||
return Task.FromResult<RepartoBancasDto?>(reparto);
|
||||
}
|
||||
|
||||
public Task<List<string[]>?> GetTelegramasTotalizadosAsync(string authToken, string distritoId, string seccionId)
|
||||
{
|
||||
var lista = new List<string[]> { new[] { $"02{seccionId}0001M" }, new[] { $"02{seccionId}0002M" } };
|
||||
return Task.FromResult<List<string[]>?>(lista);
|
||||
}
|
||||
|
||||
public Task<TelegramaFileDto?> GetTelegramaFileAsync(string authToken, string mesaId)
|
||||
{
|
||||
var file = new TelegramaFileDto { NombreArchivo = mesaId, Imagen = "FAKE_BASE64_PDF_CONTENT", FechaEscaneo = DateTime.UtcNow.AddMinutes(-10).ToString("o"), FechaTotalizacion = DateTime.UtcNow.ToString("o") };
|
||||
return Task.FromResult<TelegramaFileDto?>(file);
|
||||
}
|
||||
|
||||
public Task<List<CategoriaDto>?> GetCategoriasAsync(string authToken)
|
||||
{
|
||||
_logger.LogInformation("Simulando obtención de Categorías Electorales...");
|
||||
var categorias = new List<CategoriaDto>
|
||||
{
|
||||
new() { CategoriaId = 5, Nombre = "DIPUTADOS NACIONALES", Orden = 1 },
|
||||
new() { CategoriaId = 6, Nombre = "SENADORES NACIONALES", Orden = 2 }
|
||||
};
|
||||
return Task.FromResult<List<CategoriaDto>?>(categorias);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public interface IElectoralApiService
|
||||
Task<string?> GetAuthTokenAsync();
|
||||
|
||||
// Métodos para catálogos
|
||||
Task<List<CatalogoDto>?> GetCatalogoCompletoAsync(string authToken);
|
||||
Task<List<CatalogoDto>?> GetCatalogoAmbitosAsync(string authToken, int categoriaId);
|
||||
Task<List<AgrupacionDto>?> GetAgrupacionesAsync(string authToken, string distritoId, int categoriaId);
|
||||
|
||||
// Métodos para resultados y datos dinámicos
|
||||
|
||||
Reference in New Issue
Block a user