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 }