move get funcs to db

This commit is contained in:
sentriz
2019-07-05 17:10:11 +01:00
parent 1ab24db5d7
commit b6b3043765
13 changed files with 79 additions and 73 deletions

View File

@@ -3,10 +3,9 @@ package handler
import (
"html/template"
"github.com/jinzhu/gorm"
"github.com/wader/gormstore"
"github.com/sentriz/gonic/model"
"github.com/sentriz/gonic/db"
)
type contextKey int
@@ -17,35 +16,8 @@ const (
)
type Controller struct {
DB *gorm.DB
DB *db.DB
SessDB *gormstore.Store
Templates map[string]*template.Template
MusicPath string
}
func (c *Controller) GetSetting(key string) string {
setting := &model.Setting{}
c.DB.
Where("key = ?", key).
First(setting)
return setting.Value
}
func (c *Controller) SetSetting(key, value string) {
c.DB.
Where(model.Setting{Key: key}).
Assign(model.Setting{Value: value}).
FirstOrCreate(&model.Setting{})
}
func (c *Controller) GetUserFromName(name string) *model.User {
user := &model.User{}
err := c.DB.
Where("name = ?", name).
First(user).
Error
if gorm.IsRecordNotFoundError(err) {
return nil
}
return user
}