up
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ClienteDocumento almacena los archivos adjuntos de un cliente.
|
||||
type ClienteDocumento struct {
|
||||
gorm.Model
|
||||
ClienteID uint `json:"cliente_id" gorm:"column:cliente_id;not null;index"`
|
||||
Nombre string `json:"nombre" gorm:"column:nombre"` // nombre descriptivo del doc
|
||||
Archivo string `json:"archivo" gorm:"column:archivo"` // ruta relativa en disco
|
||||
OriginalName string `json:"original_name" gorm:"column:original_name"` // nombre original del archivo
|
||||
TipoMime string `json:"tipo_mime" gorm:"column:tipo_mime"`
|
||||
Tamanio int64 `json:"tamanio" gorm:"column:tamanio"` // bytes
|
||||
FechaExpedicion *time.Time `json:"fecha_expedicion" gorm:"column:fecha_expedicion"` // opcional
|
||||
}
|
||||
|
||||
func (ClienteDocumento) TableName() string { return "cliente_documentos" }
|
||||
|
||||
func GetDocumentosByCliente(clienteID uint) ([]ClienteDocumento, error) {
|
||||
var items []ClienteDocumento
|
||||
err := app.Http.Database.DB.
|
||||
Where("cliente_id = ?", clienteID).
|
||||
Order("created_at DESC").
|
||||
Find(&items).Error
|
||||
return items, err
|
||||
}
|
||||
|
||||
func CreateClienteDocumento(d *ClienteDocumento) error {
|
||||
return app.Http.Database.DB.Create(d).Error
|
||||
}
|
||||
|
||||
func GetClienteDocumentoByID(id uint) (*ClienteDocumento, error) {
|
||||
var d ClienteDocumento
|
||||
if err := app.Http.Database.DB.First(&d, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &d, nil
|
||||
}
|
||||
|
||||
func DeleteClienteDocumento(id uint) error {
|
||||
return app.Http.Database.DB.Delete(&ClienteDocumento{}, id).Error
|
||||
}
|
||||
@@ -16,6 +16,7 @@ type Contrato struct {
|
||||
FechaInicio time.Time `json:"fecha_inicio" gorm:"column:fecha_inicio"`
|
||||
FechaVencimiento time.Time `json:"fecha_vencimiento" gorm:"column:fecha_vencimiento"`
|
||||
PrecioAcordado float64 `json:"precio_acordado" gorm:"column:precio_acordado"`
|
||||
Moneda string `json:"moneda" gorm:"column:moneda;default:'COP'"`
|
||||
Estado string `json:"estado" gorm:"column:estado;default:'activo'"` // activo | vencido | cancelado | renovado
|
||||
AutoRenovar bool `json:"auto_renovar" gorm:"column:auto_renovar;default:false"`
|
||||
Notas string `json:"notas" gorm:"column:notas"`
|
||||
@@ -160,6 +161,7 @@ func UpdateContrato(c Contrato, servicioIDs []uint) error {
|
||||
"fecha_inicio": c.FechaInicio,
|
||||
"fecha_vencimiento": c.FechaVencimiento,
|
||||
"precio_acordado": c.PrecioAcordado,
|
||||
"moneda": c.Moneda,
|
||||
"estado": c.Estado,
|
||||
"auto_renovar": c.AutoRenovar,
|
||||
"notas": c.Notas,
|
||||
|
||||
@@ -17,6 +17,7 @@ type SaasProducto struct {
|
||||
Servicio *Servicio `json:"servicio" gorm:"foreignKey:ServicioID"`
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
Orden int `json:"orden" gorm:"column:orden;default:0"`
|
||||
HealthURL string `json:"health_url" gorm:"column:health_url"` // URL para health check (opcional)
|
||||
}
|
||||
|
||||
func (SaasProducto) TableName() string { return "saas_productos" }
|
||||
@@ -74,6 +75,7 @@ func UpdateSaasProducto(s *SaasProducto) error {
|
||||
"servicio_id": s.ServicioID,
|
||||
"activo": s.Activo,
|
||||
"orden": s.Orden,
|
||||
"health_url": s.HealthURL,
|
||||
}).Error
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TelegramConfig almacena un bot configurado con su chat_id de destino.
|
||||
type TelegramConfig struct {
|
||||
gorm.Model
|
||||
Nombre string `json:"nombre" gorm:"column:nombre;not null"`
|
||||
BotToken string `json:"bot_token" gorm:"column:bot_token;type:text;not null"`
|
||||
ChatID string `json:"chat_id" gorm:"column:chat_id;not null"` // puede ser número o @canal
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
Notas string `json:"notas" gorm:"column:notas;type:text"`
|
||||
}
|
||||
|
||||
func (TelegramConfig) TableName() string { return "telegram_configs" }
|
||||
|
||||
// TelegramLog registra cada mensaje enviado.
|
||||
type TelegramLog struct {
|
||||
gorm.Model
|
||||
TelegramConfigID uint `json:"telegram_config_id" gorm:"column:telegram_config_id;index"`
|
||||
TelegramConfig TelegramConfig `json:"telegram_config" gorm:"foreignKey:TelegramConfigID"`
|
||||
Titulo string `json:"titulo" gorm:"column:titulo"`
|
||||
Mensaje string `json:"mensaje" gorm:"column:mensaje;type:text"`
|
||||
Estado string `json:"estado" gorm:"column:estado"` // ok | failed
|
||||
ErrorMsg string `json:"error_msg" gorm:"column:error_msg;type:text"`
|
||||
}
|
||||
|
||||
func (TelegramLog) TableName() string { return "telegram_logs" }
|
||||
|
||||
// ─── Queries ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func GetAllTelegramConfigs() ([]TelegramConfig, error) {
|
||||
var items []TelegramConfig
|
||||
err := app.Http.Database.DB.Order("created_at DESC").Find(&items).Error
|
||||
return items, err
|
||||
}
|
||||
|
||||
func GetTelegramConfigByID(id uint) (*TelegramConfig, error) {
|
||||
var item TelegramConfig
|
||||
err := app.Http.Database.DB.First(&item, id).Error
|
||||
return &item, err
|
||||
}
|
||||
|
||||
func CreateTelegramConfig(c *TelegramConfig) error {
|
||||
return app.Http.Database.DB.Create(c).Error
|
||||
}
|
||||
|
||||
func UpdateTelegramConfig(c *TelegramConfig) error {
|
||||
return app.Http.Database.DB.Model(&TelegramConfig{}).Where("id = ?", c.ID).Updates(map[string]interface{}{
|
||||
"nombre": c.Nombre,
|
||||
"bot_token": c.BotToken,
|
||||
"chat_id": c.ChatID,
|
||||
"activo": c.Activo,
|
||||
"notas": c.Notas,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func DeleteTelegramConfig(id uint) error {
|
||||
return app.Http.Database.DB.Delete(&TelegramConfig{}, id).Error
|
||||
}
|
||||
|
||||
func GetTelegramLogs(limit, offset int) ([]TelegramLog, int64, error) {
|
||||
var items []TelegramLog
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&TelegramLog{}).Preload("TelegramConfig")
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := db.Order("created_at DESC").Limit(limit).Offset(offset).Find(&items).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return items, total, nil
|
||||
}
|
||||
|
||||
func CreateTelegramLog(l *TelegramLog) error {
|
||||
return app.Http.Database.DB.Create(l).Error
|
||||
}
|
||||
Reference in New Issue
Block a user