Progress on account and dashboard save/load
This commit is contained in:
@@ -35,6 +35,7 @@ func Init() {
|
||||
models.GetDashboard = GetDashboard
|
||||
models.SaveDashboard = SaveDashboard
|
||||
models.SearchQuery = SearchQuery
|
||||
models.DeleteDashboard = DeleteDashboard
|
||||
}
|
||||
|
||||
func LoadModelsConfig() {
|
||||
|
||||
@@ -27,8 +27,8 @@ func CreateAccount(account *models.Account) error {
|
||||
func GetAccount(id int64) (*models.Account, error) {
|
||||
var err error
|
||||
|
||||
account := &models.Account{Id: id}
|
||||
has, err := x.Get(account)
|
||||
var account models.Account
|
||||
has, err := x.Id(id).Get(&account)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -36,7 +36,11 @@ func GetAccount(id int64) (*models.Account, error) {
|
||||
return nil, models.ErrAccountNotFound
|
||||
}
|
||||
|
||||
return account, nil
|
||||
if account.UsingAccountId == 0 {
|
||||
account.UsingAccountId = account.Id
|
||||
}
|
||||
|
||||
return &account, nil
|
||||
}
|
||||
|
||||
func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
|
||||
|
||||
@@ -47,8 +47,18 @@ func SearchQuery(query string, accountId int64) ([]*models.SearchResult, error)
|
||||
sess := x.Limit(100, 0).Where("account_id=?", accountId)
|
||||
sess.Table("Dashboard")
|
||||
|
||||
var results []*models.SearchResult
|
||||
results := make([]*models.SearchResult, 0)
|
||||
err := sess.Find(&results)
|
||||
|
||||
return results, err
|
||||
}
|
||||
|
||||
func DeleteDashboard(slug string, accountId int64) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
rawSql := "DELETE FROM Dashboard WHERE account_id=? and slug=?"
|
||||
_, err := sess.Exec(rawSql, accountId, slug)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user