feat(infra): implement RefreshTokenRepository with Dapper and add GetByIdAsync to UsuarioRepository

This commit is contained in:
2026-04-14 13:28:29 -03:00
parent e405c0453b
commit 0c809da633
2 changed files with 166 additions and 2 deletions

View File

@@ -32,7 +32,32 @@ public sealed class UsuarioRepository : IUsuarioRepository
if (row is null) return null;
return new Usuario(
return MapRow(row);
}
public async Task<Usuario?> GetByIdAsync(int id, CancellationToken ct = default)
{
const string sql = """
SELECT
Id, Username, PasswordHash,
Nombre, Apellido, Email,
Rol, PermisosJson, Activo
FROM dbo.Usuario
WHERE Id = @Id
""";
await using var connection = _connectionFactory.CreateConnection();
await connection.OpenAsync();
var row = await connection.QuerySingleOrDefaultAsync<UsuarioRow>(sql, new { Id = id });
if (row is null) return null;
return MapRow(row);
}
private static Usuario MapRow(UsuarioRow row)
=> new(
id: row.Id,
username: row.Username,
passwordHash: row.PasswordHash,
@@ -43,7 +68,6 @@ public sealed class UsuarioRepository : IUsuarioRepository
permisosJson: row.PermisosJson,
activo: row.Activo
);
}
// Flat DTO for Dapper mapping (avoids polluting domain entity with Dapper attributes)
private sealed record UsuarioRow(