enhanced account console command

This commit is contained in:
Radu Ioan Fericean
2015-07-06 18:11:09 +03:00
parent 5aa5684aa0
commit c5b321a3be
4 changed files with 21 additions and 20 deletions

View File

@@ -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")
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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