feat(prov_servidor): add many2many integrations linking
- ProvServidor model: add Integraciones []Submodules (many2many:prov_servidor_submodules) - GetAllProvServidor: preload Integraciones - SetProvServidorIntegraciones: new model func to replace associations - New endpoint PUT /app/provservidor/:id/integraciones - GetSubmodules: support ?limit= query param - prov_servidor.html: show integrations as badges in table, view modal, and edit modal with checkboxes to select one or more existing submodules Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
parent
c834e40e83
commit
b4b60810a1
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
type ProvServidor struct {
|
||||
gorm.Model
|
||||
Nombre string `json:"nombre" gorm:"column:nombre"`
|
||||
Nombre string `json:"nombre" gorm:"column:nombre"`
|
||||
Integraciones []Submodules `json:"integraciones" gorm:"many2many:prov_servidor_submodules;"`
|
||||
}
|
||||
|
||||
func (ProvServidor) TableName() string {
|
||||
@@ -30,7 +31,7 @@ func GetAllProvServidor(search string) ([]ProvServidor, int64, error) {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if err := db.Order("created_at DESC").Find(&items).Error; err != nil {
|
||||
if err := db.Preload("Integraciones").Order("created_at DESC").Find(&items).Error; err != nil {
|
||||
log.Printf("Error retrieving proveedores: %v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -58,3 +59,19 @@ func DeleteProvServidor(provServidor ProvServidor) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetIntegraciones reemplaza todas las integraciones del proveedor con los IDs dados.
|
||||
func SetProvServidorIntegraciones(provServidorID uint, submoduleIDs []uint) error {
|
||||
db := app.Http.Database.DB
|
||||
var prov ProvServidor
|
||||
if err := db.First(&prov, provServidorID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var subs []Submodules
|
||||
if len(submoduleIDs) > 0 {
|
||||
if err := db.Where("id IN ?", submoduleIDs).Find(&subs).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return db.Model(&prov).Association("Integraciones").Replace(subs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user