sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

[host] models relink with foreignkey

This commit is contained in:
Martin Geno 2016-10-18 20:26:17 +02:00
parent fd6fb63371
commit cdca628846
3 changed files with 23 additions and 16 deletions

View File

@ -42,9 +42,9 @@ func databaseList(ctx context.Context, w http.ResponseWriter, r *http.Request) (
logger := log.GetLog(r, "databaselist")
var database []*Database
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
dbconnection.Find(&database)
dbconnection.Preload("Profil").Preload("Profil.Login").Find(&database)
} else {
dbconnection.Where("profil = ?", profil.ID).Find(&database)
dbconnection.Where("profil = ?", profil.ID).Preload("Profil").Find(&database)
}
logger.Info("done")
returndata = database

View File

@ -42,7 +42,7 @@ func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (re
logger := log.GetLog(r, "domainlist")
var domain []*Domain
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
dbconnection.Find(&domain)
dbconnection.Preload("Profil").Preload("Profil.Login").Find(&domain)
} else {
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
}

View File

@ -2,13 +2,16 @@ package host
import (
"github.com/jinzhu/gorm"
"dev.sum7.eu/sum7/warehost/system"
)
// Profil struct
type Profil struct {
ID int64
LoginID int64 `sql:"type:bigint NOT NULL UNIQUE REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
Reseller bool `sql:"default:false;column:reseller" json:"reseller"`
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"`
}
// TableName of struct
@ -17,12 +20,13 @@ func (Profil) TableName() string { return "host_profil" }
// Domain struct
type Domain struct {
ID int64
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"profil"`
FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"`
Code string `sql:"type:varchar(255);column:code" json:"-"`
Active bool `sql:"default:false;column:active" json:"active"`
Mail bool `sql:"default:false;column:mail" json:"mail"`
Web bool `sql:"default:false;column:web" json:"web"`
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"`
Code string `sql:"type:varchar(255);column:code" json:"-"`
Active bool `sql:"default:false;column:active" json:"active"`
Mail bool `sql:"default:false;column:mail" json:"mail"`
Web bool `sql:"default:false;column:web" json:"web"`
}
// TableName of struct
@ -31,7 +35,8 @@ func (Domain) TableName() string { return "host_domain" }
// Web struct
type Web struct {
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"`
PHP bool `sql:"default:false;column:php" json:"php"`
SSL bool `sql:"default:true;column:ssl" json:"ssl"`
@ -48,7 +53,8 @@ func (Web) TableName() string { return "host_web" }
// Mail struct
type Mail struct {
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"`
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"`
@ -60,9 +66,10 @@ func (Mail) TableName() string { return "host_mail" }
// Database struct
type Database struct {
ID int64
ProfilID int64 `sql:"type:bigint NOT NULL REFERENCES host_profil(id) ON UPDATE CASCADE ON DELETE CASCADE;column:profil" json:"profil"`
Password string `sql:"type:varchar(255);column:password" json:"password"`
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
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"`
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
}
// TableName of struct