refactor(infra): eliminar LegacySeedMap/NormalizeUpperSnakeToPascal de IngresosBrutosRepository
This commit is contained in:
@@ -12,9 +12,11 @@ namespace SIGCM2.Infrastructure.Persistence;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dapper implementation of <see cref="IIngresosBrutosRepository"/>.
|
/// Dapper implementation of <see cref="IIngresosBrutosRepository"/>.
|
||||||
/// Provincia is persisted as the enum member name (PascalCase, e.g. "BuenosAires") via ToString().
|
/// Provincia is persisted as the enum member name (PascalCase, e.g. "BuenosAires") via ToString().
|
||||||
/// On read, it is parsed back via Enum.Parse<ProvinciaArgentina>.
|
/// On read, it is parsed back via Enum.Parse<ProvinciaArgentina> (strict PascalCase only).
|
||||||
/// Alicuota and Provincia are NEVER updated by cosmetic methods.
|
/// Alicuota and Provincia are NEVER updated by cosmetic methods.
|
||||||
/// GetHistorialAsync uses a recursive CTE to walk the PredecesorId chain.
|
/// GetHistorialAsync uses a recursive CTE to walk the PredecesorId chain.
|
||||||
|
/// Note: As of V014 T700 cleanup, seed values are stored in PascalCase — legacy UPPER_SNAKE_CASE
|
||||||
|
/// support (LegacySeedMap / NormalizeUpperSnakeToPascal) has been removed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class IngresosBrutosRepository : IIngresosBrutosRepository
|
public sealed class IngresosBrutosRepository : IIngresosBrutosRepository
|
||||||
{
|
{
|
||||||
@@ -254,60 +256,19 @@ public sealed class IngresosBrutosRepository : IIngresosBrutosRepository
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a Provincia string from DB to ProvinciaArgentina enum.
|
/// Parses a Provincia string from DB to ProvinciaArgentina enum.
|
||||||
/// Handles both PascalCase (e.g. "BuenosAires" — written by this repo) and
|
/// Since T700 cleanup, the seed stores PascalCase values matching enum.ToString().
|
||||||
/// UPPER_SNAKE_CASE legacy seed values (e.g. "BUENOS_AIRES" — written by V014 seed).
|
/// All values written by this repo are also PascalCase.
|
||||||
/// Strategy: try direct Enum.Parse first, then normalize UPPER_SNAKE_CASE → PascalCase.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static ProvinciaArgentina ParseProvincia(string value)
|
private static ProvinciaArgentina ParseProvincia(string value)
|
||||||
{
|
{
|
||||||
// Fast path: PascalCase written by this repo (e.g. "BuenosAires")
|
|
||||||
if (Enum.TryParse<ProvinciaArgentina>(value, ignoreCase: false, out var result))
|
if (Enum.TryParse<ProvinciaArgentina>(value, ignoreCase: false, out var result))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Slow path: UPPER_SNAKE_CASE from V014 seed (e.g. "BUENOS_AIRES" → "BuenosAires")
|
|
||||||
// Also handles CABA → CiudadAutonomaDeBuenosAires via explicit mapping
|
|
||||||
var normalized = NormalizeUpperSnakeToPascal(value);
|
|
||||||
if (Enum.TryParse<ProvinciaArgentina>(normalized, ignoreCase: false, out result))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
throw new ArgumentException(
|
throw new ArgumentException(
|
||||||
$"Cannot parse '{value}' as ProvinciaArgentina. " +
|
$"Cannot parse '{value}' as ProvinciaArgentina. " +
|
||||||
$"Expected PascalCase enum name (e.g. 'BuenosAires') or UPPER_SNAKE_CASE seed name (e.g. 'BUENOS_AIRES').");
|
$"Expected PascalCase enum name (e.g. 'BuenosAires', 'CiudadAutonomaDeBuenosAires').");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps UPPER_SNAKE_CASE seed values to PascalCase enum names.
|
|
||||||
// Explicit mappings for non-trivial conversions (CABA, multi-word with articles).
|
|
||||||
private static readonly Dictionary<string, string> LegacySeedMap = new(StringComparer.Ordinal)
|
|
||||||
{
|
|
||||||
["BUENOS_AIRES"] = nameof(ProvinciaArgentina.BuenosAires),
|
|
||||||
["CABA"] = nameof(ProvinciaArgentina.CiudadAutonomaDeBuenosAires),
|
|
||||||
["CATAMARCA"] = nameof(ProvinciaArgentina.Catamarca),
|
|
||||||
["CHACO"] = nameof(ProvinciaArgentina.Chaco),
|
|
||||||
["CHUBUT"] = nameof(ProvinciaArgentina.Chubut),
|
|
||||||
["CORDOBA"] = nameof(ProvinciaArgentina.Cordoba),
|
|
||||||
["CORRIENTES"] = nameof(ProvinciaArgentina.Corrientes),
|
|
||||||
["ENTRE_RIOS"] = nameof(ProvinciaArgentina.EntreRios),
|
|
||||||
["FORMOSA"] = nameof(ProvinciaArgentina.Formosa),
|
|
||||||
["JUJUY"] = nameof(ProvinciaArgentina.Jujuy),
|
|
||||||
["LA_PAMPA"] = nameof(ProvinciaArgentina.LaPampa),
|
|
||||||
["LA_RIOJA"] = nameof(ProvinciaArgentina.LaRioja),
|
|
||||||
["MENDOZA"] = nameof(ProvinciaArgentina.Mendoza),
|
|
||||||
["MISIONES"] = nameof(ProvinciaArgentina.Misiones),
|
|
||||||
["NEUQUEN"] = nameof(ProvinciaArgentina.Neuquen),
|
|
||||||
["RIO_NEGRO"] = nameof(ProvinciaArgentina.RioNegro),
|
|
||||||
["SALTA"] = nameof(ProvinciaArgentina.Salta),
|
|
||||||
["SAN_JUAN"] = nameof(ProvinciaArgentina.SanJuan),
|
|
||||||
["SAN_LUIS"] = nameof(ProvinciaArgentina.SanLuis),
|
|
||||||
["SANTA_CRUZ"] = nameof(ProvinciaArgentina.SantaCruz),
|
|
||||||
["SANTA_FE"] = nameof(ProvinciaArgentina.SantaFe),
|
|
||||||
["SANTIAGO_DEL_ESTERO"] = nameof(ProvinciaArgentina.SantiagoDelEstero),
|
|
||||||
["TIERRA_DEL_FUEGO"] = nameof(ProvinciaArgentina.TierraDelFuego),
|
|
||||||
["TUCUMAN"] = nameof(ProvinciaArgentina.Tucuman),
|
|
||||||
};
|
|
||||||
|
|
||||||
private static string NormalizeUpperSnakeToPascal(string value)
|
|
||||||
=> LegacySeedMap.TryGetValue(value, out var pascal) ? pascal : value;
|
|
||||||
|
|
||||||
private static bool IsUniqueViolation(SqlException ex)
|
private static bool IsUniqueViolation(SqlException ex)
|
||||||
=> ex.Number is 2627 or 2601;
|
=> ex.Number is 2627 or 2601;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user