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,12 +2,15 @@ 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"`
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"`
}
@ -17,7 +20,8 @@ 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"`
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"`
@ -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,7 +66,8 @@ 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"`
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"`
}