From c5b321a3be435dd1e97017c17fd34112cadbea97 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 6 Jul 2015 18:11:09 +0300 Subject: [PATCH 1/2] enhanced account console command --- apier/v1/accounts.go | 10 +--------- apier/v1/accounts_test.go | 12 ++++++------ console/account.go | 11 ++++++----- utils/apitpdata.go | 8 ++++++++ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go index 058bd9b04..427d4f957 100644 --- a/apier/v1/accounts.go +++ b/apier/v1/accounts.go @@ -210,15 +210,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error return nil } -type AttrGetAccounts struct { - Tenant string - Direction string - AccountIds []string - Offset int // Set the item offset - Limit int // Limit number of items retrieved -} - -func (self *ApierV1) GetAccounts(attr AttrGetAccounts, reply *[]*engine.Account) error { +func (self *ApierV1) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.Account) error { if len(attr.Tenant) == 0 { return utils.NewErrMandatoryIeMissing("Tenanat") } diff --git a/apier/v1/accounts_test.go b/apier/v1/accounts_test.go index 871f3a955..055d0cdcc 100644 --- a/apier/v1/accounts_test.go +++ b/apier/v1/accounts_test.go @@ -73,31 +73,31 @@ func TestGetAccountIds(t *testing.T) { func TestGetAccounts(t *testing.T) { var accounts []*engine.Account - var attrs AttrGetAccounts - if err := apierAcnts.GetAccounts(AttrGetAccounts{Tenant: "cgrates.org"}, &accounts); err != nil { + var attrs utils.AttrGetAccounts + if err := apierAcnts.GetAccounts(utils.AttrGetAccounts{Tenant: "cgrates.org"}, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 3 { t.Errorf("Accounts returned: %+v", accounts) } - attrs = AttrGetAccounts{Tenant: "itsyscom.com"} + attrs = utils.AttrGetAccounts{Tenant: "itsyscom.com"} if err := apierAcnts.GetAccounts(attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 2 { t.Errorf("Accounts returned: %+v", accounts) } - attrs = AttrGetAccounts{Tenant: "cgrates.org", AccountIds: []string{"account1"}} + attrs = utils.AttrGetAccounts{Tenant: "cgrates.org", AccountIds: []string{"account1"}} if err := apierAcnts.GetAccounts(attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 1 { t.Errorf("Accounts returned: %+v", accounts) } - attrs = AttrGetAccounts{Tenant: "itsyscom.com", AccountIds: []string{"INVALID"}} + attrs = utils.AttrGetAccounts{Tenant: "itsyscom.com", AccountIds: []string{"INVALID"}} if err := apierAcnts.GetAccounts(attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 0 { t.Errorf("Accounts returned: %+v", accounts) } - attrs = AttrGetAccounts{Tenant: "INVALID"} + attrs = utils.AttrGetAccounts{Tenant: "INVALID"} if err := apierAcnts.GetAccounts(attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 0 { diff --git a/console/account.go b/console/account.go index 78704a882..e94e47431 100644 --- a/console/account.go +++ b/console/account.go @@ -26,8 +26,8 @@ import ( func init() { c := &CmdGetAccount{ name: "account", - rpcMethod: "ApierV1.GetAccount", - rpcParams: &utils.AttrGetAccount{Direction: "*out"}, + rpcMethod: "ApierV1.GetAccounts", + rpcParams: &utils.AttrGetAccounts{Direction: "*out"}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -37,7 +37,7 @@ func init() { type CmdGetAccount struct { name string rpcMethod string - rpcParams *utils.AttrGetAccount + rpcParams *utils.AttrGetAccounts *CommandExecuter } @@ -51,7 +51,7 @@ func (self *CmdGetAccount) RpcMethod() string { func (self *CmdGetAccount) RpcParams(ptr bool) interface{} { if self.rpcParams == nil { - self.rpcParams = &utils.AttrGetAccount{Direction: "*out"} + self.rpcParams = &utils.AttrGetAccounts{Direction: "*out"} } if ptr { return self.rpcParams @@ -64,5 +64,6 @@ func (self *CmdGetAccount) PostprocessRpcParams() error { } func (self *CmdGetAccount) RpcResult() interface{} { - return &engine.Account{} + a := make([]engine.Account, 0) + return &a } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index f06d74924..61b937680 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -511,6 +511,14 @@ type AttrGetAccount struct { Direction string } +type AttrGetAccounts struct { + Tenant string + Direction string + AccountIds []string + Offset int // Set the item offset + Limit int // Limit number of items retrieved +} + // Data used to do remote cache reloads via api type ApiReloadCache struct { DestinationIds []string From 47387150afc51ab2cf31ffa89bb6b768d1eefa0a Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 6 Jul 2015 21:13:04 +0300 Subject: [PATCH 2/2] renamed account console command to accounts --- console/{account.go => accounts.go} | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename console/{account.go => accounts.go} (79%) diff --git a/console/account.go b/console/accounts.go similarity index 79% rename from console/account.go rename to console/accounts.go index e94e47431..f4c4b8ffc 100644 --- a/console/account.go +++ b/console/accounts.go @@ -24,8 +24,8 @@ import ( ) func init() { - c := &CmdGetAccount{ - name: "account", + c := &CmdGetAccounts{ + name: "accounts", rpcMethod: "ApierV1.GetAccounts", rpcParams: &utils.AttrGetAccounts{Direction: "*out"}, } @@ -34,22 +34,22 @@ func init() { } // Commander implementation -type CmdGetAccount struct { +type CmdGetAccounts struct { name string rpcMethod string rpcParams *utils.AttrGetAccounts *CommandExecuter } -func (self *CmdGetAccount) Name() string { +func (self *CmdGetAccounts) Name() string { return self.name } -func (self *CmdGetAccount) RpcMethod() string { +func (self *CmdGetAccounts) RpcMethod() string { return self.rpcMethod } -func (self *CmdGetAccount) RpcParams(ptr bool) interface{} { +func (self *CmdGetAccounts) RpcParams(ptr bool) interface{} { if self.rpcParams == nil { self.rpcParams = &utils.AttrGetAccounts{Direction: "*out"} } @@ -59,11 +59,11 @@ func (self *CmdGetAccount) RpcParams(ptr bool) interface{} { return *self.rpcParams } -func (self *CmdGetAccount) PostprocessRpcParams() error { +func (self *CmdGetAccounts) PostprocessRpcParams() error { return nil } -func (self *CmdGetAccount) RpcResult() interface{} { +func (self *CmdGetAccounts) RpcResult() interface{} { a := make([]engine.Account, 0) return &a }