Tried postgres

This commit is contained in:
Torkel Ödegaard
2014-11-24 10:17:13 +01:00
parent a8f915f049
commit be781bdb98
9 changed files with 76 additions and 49 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
resp["message"] = message
}
ctx.HTML(status, "index")
ctx.JSON(status, resp)
}
func (ctx *Context) JsonBody(model interface{}) bool {
+3 -3
View File
@@ -40,12 +40,12 @@ func AddCollaborator(c *middleware.Context) {
accountToAdd, err := models.GetAccountByLogin(model.Email)
if err != nil {
c.JSON(404, utils.DynMap{"message": "Collaborator not found"})
c.JsonApiErr(404, "Collaborator not found", nil)
return
}
if accountToAdd.Id == c.UserAccount.Id {
c.JSON(400, utils.DynMap{"message": "Cannot add yourself as collaborator"})
c.JsonApiErr(400, "Cannot add yourself as collaborator", nil)
return
}
@@ -53,7 +53,7 @@ func AddCollaborator(c *middleware.Context) {
err = models.AddCollaborator(collaborator)
if err != nil {
c.JSON(400, utils.DynMap{"message": err.Error()})
c.JsonApiErr(500, "Could not add collaborator", err)
return
}
-29
View File
@@ -1,29 +0,0 @@
package server
import (
"github.com/torkelo/grafana-pro/pkg/api"
"github.com/torkelo/grafana-pro/pkg/configuration"
"github.com/torkelo/grafana-pro/pkg/stores"
)
type Server struct {
HttpServer *api.HttpServer
Store stores.Store
}
func NewServer(cfg *configuration.Cfg) (*Server, error) {
store := stores.New()
httpServer := api.NewHttpServer(cfg, store)
return &Server{
HttpServer: httpServer,
Store: store,
}, nil
}
func (self *Server) ListenAndServe() error {
self.HttpServer.ListenAndServe()
return nil
}
+1 -1
View File
@@ -50,7 +50,7 @@ func LoadModelsConfig() {
DbCfg.Name = setting.Cfg.MustValue("database", "name")
DbCfg.User = setting.Cfg.MustValue("database", "user")
if len(DbCfg.Pwd) == 0 {
DbCfg.Pwd = setting.Cfg.MustValue("database", "passwd")
DbCfg.Pwd = setting.Cfg.MustValue("database", "password")
}
DbCfg.SslMode = setting.Cfg.MustValue("database", "ssl_mode")
DbCfg.Path = setting.Cfg.MustValue("database", "path", "data/grafana.db")
+6 -6
View File
@@ -61,9 +61,9 @@ func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
func GetCollaboratorsForAccount(accountId int64) ([]*models.CollaboratorInfo, error) {
collaborators := make([]*models.CollaboratorInfo, 0)
sess := x.Table("Collaborator")
sess.Join("INNER", "Account", "Account.id=Collaborator.account_Id")
sess.Where("Collaborator.for_account_id=?", accountId)
sess := x.Table("collaborator")
sess.Join("INNER", "account", "account.id=collaborator.account_Id")
sess.Where("collaborator.for_account_id=?", accountId)
err := sess.Find(&collaborators)
return collaborators, err
@@ -91,9 +91,9 @@ func AddCollaborator(collaborator *models.Collaborator) error {
func GetOtherAccountsFor(accountId int64) ([]*models.OtherAccount, error) {
collaborators := make([]*models.OtherAccount, 0)
sess := x.Table("Collaborator")
sess.Join("INNER", "Account", "Account.id=Collaborator.account_Id")
sess.Where("Collaborator.account_id=?", accountId)
sess := x.Table("collaborator")
sess.Join("INNER", "account", "account.id=collaborator.account_Id")
sess.Where("account_id=?", accountId)
err := sess.Find(&collaborators)
return collaborators, err
}