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") 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

View File

@ -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)
} }

View File

@ -2,13 +2,16 @@ 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:"-"`
Reseller bool `sql:"default:false;column:reseller" json:"reseller"` Login *system.Login `gorm:"foreignkey:Login;" json:"login"`
Reseller bool `sql:"default:false;column:reseller" json:"reseller"`
} }
// TableName of struct // TableName of struct
@ -17,12 +20,13 @@ 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:"-"`
FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"` Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
Code string `sql:"type:varchar(255);column:code" json:"-"` FQDN string `sql:"type:varchar(255) NOT NULL UNIQUE;column:fqdn" json:"fqdn"`
Active bool `sql:"default:false;column:active" json:"active"` Code string `sql:"type:varchar(255);column:code" json:"-"`
Mail bool `sql:"default:false;column:mail" json:"mail"` Active bool `sql:"default:false;column:active" json:"active"`
Web bool `sql:"default:false;column:web" json:"web"` Mail bool `sql:"default:false;column:mail" json:"mail"`
Web bool `sql:"default:false;column:web" json:"web"`
} }
// TableName of struct // TableName of struct
@ -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,9 +66,10 @@ 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:"-"`
Password string `sql:"type:varchar(255);column:password" json:"password"` Profil *Profil `gorm:"foreignkey:Profil;" json:"profil"`
Comment string `sql:"type:varchar(255);column:comment" json:"comment"` Password string `sql:"type:varchar(255);column:password" json:"password"`
Comment string `sql:"type:varchar(255);column:comment" json:"comment"`
} }
// TableName of struct // TableName of struct