More work on collaborators, and sql store
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user