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

58 lines
1.7 KiB
Go
Raw Normal View History

2016-09-11 23:04:26 +02:00
package web
import (
"net/http"
2016-10-11 20:16:24 +02:00
"goji.io/pat"
"golang.org/x/net/context"
2016-09-11 23:04:26 +02:00
2016-10-11 20:16:24 +02:00
libapi "dev.sum7.eu/sum7/warehost/lib/api"
2016-09-11 23:04:26 +02:00
)
// DomainList to list domains
2016-10-11 20:16:24 +02:00
func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
2016-09-11 23:04:26 +02:00
returndata = false
2016-10-11 20:16:24 +02:00
logger := log.GetLog(r, "domainlist")
2016-09-11 23:04:26 +02:00
var domain []*Domain
2016-10-11 20:16:24 +02:00
dbconnection.Where("website = ?", ctx.Value("websiteid").(int64)).Preload("Domains").Find(&domain)
2016-09-11 23:04:26 +02:00
logger.Info("done")
returndata = domain
return
}
// DomainAdd to add domain
2016-10-11 20:16:24 +02:00
func domainAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
2016-09-11 23:04:26 +02:00
returndata = false
2016-10-11 20:16:24 +02:00
logger := log.GetLog(r, "domainadd")
2016-09-11 23:04:26 +02:00
domain := &Domain{
2016-10-11 20:16:24 +02:00
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(ctx, "domain"),
2016-09-11 23:04:26 +02:00
}
2016-10-11 20:16:24 +02:00
if err := dbconnection.Create(domain).Error; err != nil {
2016-09-11 23:04:26 +02:00
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
2016-10-11 20:16:24 +02:00
func domainDelete(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
2016-09-11 23:04:26 +02:00
returndata = false
2016-10-11 20:16:24 +02:00
logger := log.GetLog(r, "domaindelete")
2016-09-11 23:04:26 +02:00
domain := &Domain{
2016-10-11 20:16:24 +02:00
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(ctx, "domain"),
2016-09-11 23:04:26 +02:00
}
2016-10-11 20:16:24 +02:00
if err := dbconnection.Unscoped().Delete(domain).Error; err != nil {
2016-09-11 23:04:26 +02:00
logger.Error("database: during delete website Domain")
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
return
}
returndata = true
logger.Info("done")
return
}