feat: funciones Go para API Metabase y tipo MetabaseClient
Añade funciones Go stub para la API de Metabase en dominio infra: auth, CRUD de cards, dashboards y users, execute_query y execute_card. Incluye tipo MetabaseClient y helper HTTP compartido. Todas las funciones son impuras con stubs not-implemented.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
---
|
||||
name: metabase_update_dashboard
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func MetabaseUpdateDashboard(client MetabaseClient, dashboardID int, fields map[string]any) (map[string]any, error)"
|
||||
description: "Actualiza un dashboard en Metabase incluyendo metadata, cards y tabs. El campo dashcards representa el estado completo deseado: cards nuevas con ID negativo, existentes con ID positivo, omitidas se eliminan. Endpoint: PUT /api/dashboard/:id."
|
||||
tags: [metabase, dashboard, update, cards, api]
|
||||
uses_functions: []
|
||||
uses_types: [MetabaseClient_go_infra]
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [fmt]
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "functions/infra/metabase_update_dashboard.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
// Cambiar nombre
|
||||
MetabaseUpdateDashboard(client, 1, map[string]any{
|
||||
"name": "Updated Dashboard",
|
||||
})
|
||||
|
||||
// Agregar una card al dashboard
|
||||
// Primero obtener las dashcards existentes
|
||||
dash, _ := MetabaseGetDashboard(client, 1)
|
||||
existingCards := dash["dashcards"].([]any)
|
||||
|
||||
// Construir nuevo array con las existentes + la nueva
|
||||
dashcards := make([]map[string]any, 0)
|
||||
for _, dc := range existingCards {
|
||||
dashcards = append(dashcards, dc.(map[string]any))
|
||||
}
|
||||
// Agregar nueva card (ID negativo = nueva)
|
||||
dashcards = append(dashcards, map[string]any{
|
||||
"id": -1, "card_id": 55, "size_x": 6, "size_y": 4, "col": 0, "row": 0,
|
||||
})
|
||||
|
||||
MetabaseUpdateDashboard(client, 1, map[string]any{
|
||||
"dashcards": dashcards,
|
||||
})
|
||||
|
||||
// Archivar dashboard (soft-delete)
|
||||
MetabaseUpdateDashboard(client, 1, map[string]any{"archived": true})
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
### Gestion de dashcards (IMPORTANTE)
|
||||
|
||||
El array `dashcards` representa el **estado completo deseado** del dashboard:
|
||||
|
||||
| Accion | Como hacerlo |
|
||||
|--------|-------------|
|
||||
| Agregar card | Incluir con **ID negativo** (-1, -2, etc.) |
|
||||
| Actualizar card | Incluir con su **ID positivo** existente |
|
||||
| Eliminar card | **Omitir** del array |
|
||||
| No cambiar cards | No incluir el campo dashcards |
|
||||
|
||||
**Flujo tipico para agregar una card:**
|
||||
1. `MetabaseGetDashboard` para obtener dashcards existentes
|
||||
2. Copiar las existentes al nuevo array
|
||||
3. Agregar la nueva con ID negativo
|
||||
4. Enviar el array completo
|
||||
|
||||
### Estructura de una dashcard
|
||||
|
||||
```go
|
||||
map[string]any{
|
||||
"id": -1, // negativo = nueva, positivo = existente
|
||||
"card_id": 42, // ID de la card/pregunta
|
||||
"size_x": 6, // ancho (1-18)
|
||||
"size_y": 4, // alto
|
||||
"col": 0, // columna (0-based)
|
||||
"row": 0, // fila (0-based)
|
||||
"dashboard_tab_id": nil, // tab (nil = sin tabs)
|
||||
"parameter_mappings": []map[string]any{}, // mapeo de filtros
|
||||
"visualization_settings": map[string]any{}, // settings custom
|
||||
}
|
||||
```
|
||||
|
||||
### Gestion de tabs
|
||||
|
||||
```go
|
||||
map[string]any{
|
||||
"tabs": []map[string]any{
|
||||
{"id": 1, "name": "Overview"}, // tab existente
|
||||
{"id": -1, "name": "Details"}, // tab nuevo (ID negativo)
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Campos actualizables
|
||||
|
||||
| Campo | Tipo | Descripcion |
|
||||
|-------|------|-------------|
|
||||
| name | string | Nombre del dashboard |
|
||||
| description | string | Descripcion |
|
||||
| archived | bool | Archivar/desarchivar |
|
||||
| dashcards | []map | Estado completo de cards |
|
||||
| tabs | []map | Tabs del dashboard |
|
||||
| parameters | []map | Filtros del dashboard |
|
||||
| collection_id | int | Mover a otra coleccion |
|
||||
Reference in New Issue
Block a user