[host] models relink with foreignkey
This commit is contained in:
parent
fd6fb63371
commit
cdca628846
|
@ -42,9 +42,9 @@ func databaseList(ctx context.Context, w http.ResponseWriter, r *http.Request) (
|
||||||
logger := log.GetLog(r, "databaselist")
|
logger := log.GetLog(r, "databaselist")
|
||||||
var database []*Database
|
var database []*Database
|
||||||
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
||||||
dbconnection.Find(&database)
|
dbconnection.Preload("Profil").Preload("Profil.Login").Find(&database)
|
||||||
} else {
|
} else {
|
||||||
dbconnection.Where("profil = ?", profil.ID).Find(&database)
|
dbconnection.Where("profil = ?", profil.ID).Preload("Profil").Find(&database)
|
||||||
}
|
}
|
||||||
logger.Info("done")
|
logger.Info("done")
|
||||||
returndata = database
|
returndata = database
|
||||||
|
|
|
@ -42,7 +42,7 @@ func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (re
|
||||||
logger := log.GetLog(r, "domainlist")
|
logger := log.GetLog(r, "domainlist")
|
||||||
var domain []*Domain
|
var domain []*Domain
|
||||||
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
||||||
dbconnection.Find(&domain)
|
dbconnection.Preload("Profil").Preload("Profil.Login").Find(&domain)
|
||||||
} else {
|
} else {
|
||||||
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
|
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,15 @@ package host
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
|
"dev.sum7.eu/sum7/warehost/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Profil struct
|
// Profil struct
|
||||||
type Profil struct {
|
type Profil struct {
|
||||||
ID int64
|
ID int64
|
||||||
LoginID int64 `sql:"type:bigint NOT NULL UNIQUE REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
LoginID int64 `sql:"type:bigint NOT NULL UNIQUE REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
|
||||||
|
Login *system.Login `gorm:"foreignkey:Login;" json:"login"`
|
||||||
Reseller bool `sql:"default:false;column:reseller" json:"reseller"`
|
Reseller bool `sql:"default:false;column:reseller" json:"reseller"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +20,8 @@ func (Profil) TableName() string { return "host_profil" }
|
||||||
// Domain struct
|
// Domain struct
|
||||||
type Domain struct {
|
type Domain struct {
|
||||||
ID int64
|
ID int64
|
||||||
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"profil"`
|
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"-"`
|
||||||
|
Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
|
||||||
FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"`
|
FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"`
|
||||||
Code string `sql:"type:varchar(255);column:code" json:"-"`
|
Code string `sql:"type:varchar(255);column:code" json:"-"`
|
||||||
Active bool `sql:"default:false;column:active" json:"active"`
|
Active bool `sql:"default:false;column:active" json:"active"`
|
||||||
|
@ -31,7 +35,8 @@ func (Domain) TableName() string { return "host_domain" }
|
||||||
// Web struct
|
// Web struct
|
||||||
type Web struct {
|
type Web struct {
|
||||||
ID int64
|
ID int64
|
||||||
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"domain"`
|
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
|
||||||
|
Domain *Domain `gorm:"foreignkey:Domain;" json:"domain"`
|
||||||
Subdomain string `sql:"type:varchar(255);column:subdomain" json:"subdomain"`
|
Subdomain string `sql:"type:varchar(255);column:subdomain" json:"subdomain"`
|
||||||
PHP bool `sql:"default:false;column:php" json:"php"`
|
PHP bool `sql:"default:false;column:php" json:"php"`
|
||||||
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
|
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
|
||||||
|
@ -48,7 +53,8 @@ func (Web) TableName() string { return "host_web" }
|
||||||
// Mail struct
|
// Mail struct
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
ID int64
|
ID int64
|
||||||
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"domain"`
|
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
|
||||||
|
Domain *Domain `gorm:"foreignkey:Domain;" json:"domain"`
|
||||||
Name string `sql:"type:varchar(255);column:name" json:"name"`
|
Name string `sql:"type:varchar(255);column:name" json:"name"`
|
||||||
Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
||||||
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
||||||
|
@ -60,7 +66,8 @@ func (Mail) TableName() string { return "host_mail" }
|
||||||
// Database struct
|
// Database struct
|
||||||
type Database struct {
|
type Database struct {
|
||||||
ID int64
|
ID int64
|
||||||
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"profil"`
|
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"-"`
|
||||||
|
Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
|
||||||
Password string `sql:"type:varchar(255);column:password" json:"password"`
|
Password string `sql:"type:varchar(255);column:password" json:"password"`
|
||||||
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
|
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue