More work on collaborators, and sql store

This commit is contained in:
Torkel Ödegaard
2014-11-21 16:43:04 +01:00
parent 4eefa73441
commit f04932aa67
9 changed files with 177 additions and 24 deletions
+3 -1
View File
@@ -27,7 +27,7 @@ var (
)
func Init() {
tables = append(tables, new(models.Account), new(models.Dashboard))
tables = append(tables, new(models.Account), new(models.Dashboard), new(models.Collaborator))
models.CreateAccount = CreateAccount
models.GetAccount = GetAccount
@@ -36,6 +36,8 @@ func Init() {
models.SaveDashboard = SaveDashboard
models.SearchQuery = SearchQuery
models.DeleteDashboard = DeleteDashboard
models.GetCollaboratorsForAccount = GetCollaboratorsForAccount
models.AddCollaborator = AddCollaborator
}
func LoadModelsConfig() {
+28
View File
@@ -57,3 +57,31 @@ func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
return account, nil
}
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")
err := sess.Find(&collaborators)
return collaborators, err
}
func AddCollaborator(collaborator *models.Collaborator) error {
var err error
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
if _, err = sess.Insert(collaborator); err != nil {
sess.Rollback()
return err
} else if err = sess.Commit(); err != nil {
return err
}
return nil
}