mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -24,34 +24,34 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetAccount{
|
||||
name: "account",
|
||||
rpcMethod: "ApierV1.GetAccount",
|
||||
rpcParams: &utils.AttrGetAccount{Direction: "*out"},
|
||||
c := &CmdGetAccounts{
|
||||
name: "accounts",
|
||||
rpcMethod: "ApierV1.GetAccounts",
|
||||
rpcParams: &utils.AttrGetAccounts{Direction: "*out"},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetAccount struct {
|
||||
type CmdGetAccounts struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *utils.AttrGetAccount
|
||||
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.AttrGetAccount{Direction: "*out"}
|
||||
self.rpcParams = &utils.AttrGetAccounts{Direction: "*out"}
|
||||
}
|
||||
if ptr {
|
||||
return self.rpcParams
|
||||
@@ -59,10 +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{} {
|
||||
return &engine.Account{}
|
||||
func (self *CmdGetAccounts) RpcResult() interface{} {
|
||||
a := make([]engine.Account, 0)
|
||||
return &a
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user