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

54 lines
1.5 KiB
Go

package web
import (
"net/http"
"goji.io/pat"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
)
// DomainList to list domains
func domainList(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger := log.GetLog(r, "domainlist")
var domain []*Domain
dbconnection.Where("website = ?", ctx.Value("websiteid").(int64)).Preload("Domains").Find(&domain)
logger.Info("done")
libapi.JSONWrite(w, r, domain, nil)
}
// DomainAdd to add domain
func domainAdd(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger := log.GetLog(r, "domainadd")
domain := &Domain{
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(r, "domain"),
}
if err := dbconnection.Create(domain).Error; err != nil {
logger.Error("database: during create website domain: ", err)
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Message: "Internal Database Error"})
return
}
logger.Info("done")
libapi.JSONWrite(w, r, true, nil)
}
// DomainDelete to delete domain
func domainDelete(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger := log.GetLog(r, "domaindelete")
domain := &Domain{
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(r, "domain"),
}
if err := dbconnection.Unscoped().Delete(domain).Error; err != nil {
logger.Error("database: during delete website Domain")
libapi.JSONWrite(w, r, false, &libapi.ErrorResult{Message: "Internal Database Error"})
return
}
logger.Info("done")
libapi.JSONWrite(w, r, true, nil)
}