49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
|
package host
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"golang.org/x/net/context"
|
||
|
|
||
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
||
|
)
|
||
|
|
||
|
func databaseList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||
|
profil := ctx.Value("profil").(*Profil)
|
||
|
returndata = false
|
||
|
logger := log.GetLog(r, "databaselist")
|
||
|
var database []*Database
|
||
|
dbconnection.Where("profil = ?", profil.ID).Find(&database)
|
||
|
logger.Info("done")
|
||
|
returndata = database
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func databaseAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||
|
profil := ctx.Value("profil").(*Profil)
|
||
|
returndata = false
|
||
|
logger := log.GetLog(r, "databaseadd")
|
||
|
|
||
|
var databaseRequest Database
|
||
|
returnerr = libapi.JSONDecoder(r.Body, &databaseRequest, w, logger)
|
||
|
if returnerr != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
database := &Database{
|
||
|
ProfilID: profil.ID,
|
||
|
Password: databaseRequest.Password,
|
||
|
Comment: databaseRequest.Comment,
|
||
|
}
|
||
|
|
||
|
if err := dbconnection.Create(database).Error; err != nil {
|
||
|
logger.Error("database: during create host database: ", err)
|
||
|
w.WriteHeader(http.StatusInternalServerError)
|
||
|
returnerr = &libapi.ErrorResult{Message: "Internal Database Error with Database"}
|
||
|
return
|
||
|
}
|
||
|
returndata = true
|
||
|
logger.Info("done")
|
||
|
return
|
||
|
}
|