[web] domains added
This commit is contained in:
parent
33f7f52f6f
commit
f1e7bacbfc
|
@ -40,6 +40,9 @@ func NewAPI(config *libconfig.Config, sessions *session.Manager, dbconnection *g
|
|||
router.GET(prefix+"/website/:websiteid/permission", InvolveWebsiteHandler(api.PermissionList, sessions, dbconnection))
|
||||
router.POST(prefix+"/website/:websiteid/permission/:loginid", InvolveWebsiteHandler(api.PermissionAdd, sessions, dbconnection))
|
||||
router.DELETE(prefix+"/website/:websiteid/permission/:loginid", InvolveWebsiteHandler(api.PermissionDelete, sessions, dbconnection))
|
||||
router.GET(prefix+"/website/:websiteid/domain", InvolveWebsiteHandler(api.DomainList, sessions, dbconnection))
|
||||
router.POST(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainAdd, sessions, dbconnection))
|
||||
router.DELETE(prefix+"/website/:websiteid/domain/:domain", InvolveWebsiteHandler(api.DomainDelete, sessions, dbconnection))
|
||||
}
|
||||
|
||||
// Involve to get Website where loggend in user has privilegs
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/astaxie/session"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
libapi "dev.sum7.de/sum7/warehost/lib/api"
|
||||
libsystem "dev.sum7.de/sum7/warehost/system"
|
||||
)
|
||||
|
||||
// DomainList to list domains
|
||||
func (api *API) DomainList(w http.ResponseWriter, r *http.Request, _ httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||
returndata = false
|
||||
logger := api.log.GetLog(r, "domainlist")
|
||||
var domain []*Domain
|
||||
api.dbconnection.Where("website = ?", websiteid).Preload("Domains").Find(&domain)
|
||||
logger.Info("done")
|
||||
returndata = domain
|
||||
return
|
||||
}
|
||||
|
||||
// DomainAdd to add domain
|
||||
func (api *API) DomainAdd(w http.ResponseWriter, r *http.Request, ps httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||
returndata = false
|
||||
logger := api.log.GetLog(r, "domainadd")
|
||||
domain := &Domain{
|
||||
WebsiteID: websiteid,
|
||||
Name: ps.ByName("domain"),
|
||||
}
|
||||
if err := api.dbconnection.Create(domain).Error; err != nil {
|
||||
logger.Error("database: during create website domain: ", err)
|
||||
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
|
||||
return
|
||||
}
|
||||
returndata = true
|
||||
logger.Info("done")
|
||||
return
|
||||
}
|
||||
|
||||
// DomainDelete to delete domain
|
||||
func (api *API) DomainDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params, sess session.Session, login *libsystem.Login, websiteid int64) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||
returndata = false
|
||||
logger := api.log.GetLog(r, "domaindelete")
|
||||
domain := &Domain{
|
||||
WebsiteID: websiteid,
|
||||
Name: ps.ByName("domain"),
|
||||
}
|
||||
if err := api.dbconnection.Unscoped().Delete(domain).Error; err != nil {
|
||||
logger.Error("database: during delete website Domain")
|
||||
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
|
||||
return
|
||||
}
|
||||
returndata = true
|
||||
logger.Info("done")
|
||||
return
|
||||
}
|
|
@ -20,7 +20,7 @@ func (Website) TableName() string { return "web_website" }
|
|||
// Domain struct
|
||||
type Domain struct {
|
||||
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website;primary_key"`
|
||||
Name string `gorm:"type:varchar(255);unique;column:name" json:"name"`
|
||||
Name string `gorm:"type:varchar(255);unique;column:name;primary_key" json:"name"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
|
|
2
webroot
2
webroot
|
@ -1 +1 @@
|
|||
Subproject commit ed433dc66f10a99f1a7ac3df538bc072e8e1881c
|
||||
Subproject commit 9e6988ddfbfe1957ba24fd556c738ab03c4e5791
|
Reference in New Issue