sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/modul/web/apidomain.go

59 lines
1.9 KiB
Go
Raw Normal View History

2016-09-11 23:04:26 +02:00
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
}