fix: coolify_configs table missing + miniwebs real status
- Add coolify_config.go model (missing from worktree branch) - Add CoolifyConfig to normal-startup AutoMigrate → creates table on next start - Fix miniwebs tab: m.activo is not in API response; fallback to vcard.estado (true/false) to show real status instead of always Inactiva - Improve miniwebs row: show url, user name, vcard status badge Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
parent
661e02ef9c
commit
5373cebf9c
@@ -0,0 +1,54 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CoolifyConfig almacena las credenciales para la API REST de Coolify.
|
||||
// Coolify expone su API en {base_url}/api/v1 con Bearer token.
|
||||
type CoolifyConfig struct {
|
||||
gorm.Model
|
||||
Nombre string `json:"nombre" gorm:"column:nombre;not null"`
|
||||
BaseURL string `json:"base_url" gorm:"column:base_url;type:text;not null"`
|
||||
ApiToken string `json:"api_token" gorm:"column:api_token;type:text;not null"`
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
}
|
||||
|
||||
func (CoolifyConfig) TableName() string { return "coolify_configs" }
|
||||
|
||||
func GetCoolifyConfig() (*CoolifyConfig, error) {
|
||||
var cfg CoolifyConfig
|
||||
if err := app.Http.Database.DB.First(&cfg).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func UpsertCoolifyConfig(nombre, baseURL, apiToken string, activo bool) (*CoolifyConfig, error) {
|
||||
var cfg CoolifyConfig
|
||||
err := app.Http.Database.DB.First(&cfg).Error
|
||||
if err != nil {
|
||||
// No existe → crear
|
||||
cfg = CoolifyConfig{
|
||||
Nombre: nombre,
|
||||
BaseURL: baseURL,
|
||||
ApiToken: apiToken,
|
||||
Activo: activo,
|
||||
}
|
||||
if createErr := app.Http.Database.DB.Create(&cfg).Error; createErr != nil {
|
||||
return nil, createErr
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
cfg.Nombre = nombre
|
||||
cfg.BaseURL = baseURL
|
||||
if apiToken != "" {
|
||||
cfg.ApiToken = apiToken
|
||||
}
|
||||
cfg.Activo = activo
|
||||
if err := app.Http.Database.DB.Save(&cfg).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user