feat(infra): implement RefreshTokenRepository with Dapper and add GetByIdAsync to UsuarioRepository
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user