Refactoring set using account

This commit is contained in:
Torkel Ödegaard
2014-12-19 13:12:47 +01:00
parent 607b0c0c0e
commit 5dcf6ff2d3
5 changed files with 64 additions and 32 deletions
+12
View File
@@ -14,6 +14,7 @@ func init() {
bus.AddHandler("sql", AddCollaborator)
bus.AddHandler("sql", GetOtherAccounts)
bus.AddHandler("sql", CreateAccount)
bus.AddHandler("sql", SetUsingAccount)
}
func CreateAccount(cmd *m.CreateAccountCommand) error {
@@ -33,6 +34,17 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
})
}
func SetUsingAccount(cmd *m.SetUsingAccountCommand) error {
return inTransaction(func(sess *xorm.Session) error {
account := m.Account{}
sess.Id(cmd.AccountId).Get(&account)
account.UsingAccountId = cmd.UsingAccountId
_, err := sess.Id(account.Id).Update(&account)
return err
})
}
func GetAccountInfo(query *m.GetAccountInfoQuery) error {
var account m.Account
has, err := x.Id(query.Id).Get(&account)
+6
View File
@@ -61,6 +61,12 @@ func TestAccountDataAccess(t *testing.T) {
So(err, ShouldBeNil)
So(query.Result[0].Email, ShouldEqual, "ac1@test.com")
})
Convey("Can set using account", func() {
cmd := m.SetUsingAccountCommand{AccountId: ac2.Id, UsingAccountId: ac1.Id}
err := SetUsingAccount(&cmd)
So(err, ShouldBeNil)
})
})
})
})