| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package sqlstore
- import (
- "github.com/torkelo/grafana-pro/pkg/models"
- )
- func CreateAccount(account *models.Account) error {
- var err error
- sess := x.NewSession()
- defer sess.Close()
- if err = sess.Begin(); err != nil {
- return err
- }
- if _, err = sess.Insert(account); err != nil {
- sess.Rollback()
- return err
- } else if err = sess.Commit(); err != nil {
- return err
- }
- return nil
- }
- func GetAccount(id int64) (*models.Account, error) {
- var err error
- var account models.Account
- has, err := x.Id(id).Get(&account)
- if err != nil {
- return nil, err
- } else if has == false {
- return nil, models.ErrAccountNotFound
- }
- if account.UsingAccountId == 0 {
- account.UsingAccountId = account.Id
- }
- return &account, nil
- }
- func GetAccountByLogin(emailOrLogin string) (*models.Account, error) {
- var err error
- account := &models.Account{Login: emailOrLogin}
- has, err := x.Get(account)
- if err != nil {
- return nil, err
- } else if has == false {
- return nil, models.ErrAccountNotFound
- }
- 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")
- sess.Where("Collaborator.for_account_id=?", accountId)
- 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
- }
- 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)
- err := sess.Find(&collaborators)
- return collaborators, err
- }
|