From ac5ca11eb872a0b06ff3ba0994ba907d5f140642 Mon Sep 17 00:00:00 2001 From: adragusin Date: Thu, 14 May 2020 18:00:27 +0300 Subject: [PATCH] Added GetAccountsCount API --- apier/v2/accounts.go | 15 +++++++++++++++ utils/apitpdata.go | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/apier/v2/accounts.go b/apier/v2/accounts.go index 201bb6f2a..cb2df7d33 100644 --- a/apier/v2/accounts.go +++ b/apier/v2/accounts.go @@ -80,6 +80,21 @@ func (apiv2 *APIerSv2) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine. return nil } +// GetAccountsCount returns the total number of accounts +func (apiv2 *APIerSv2) GetAccountsCount(attr utils.AttrGetAccountsCount, reply *int) (err error) { + if len(attr.Tenant) == 0 { + return utils.NewErrMandatoryIeMissing("Tenant") + } + var accountKeys []string + + if accountKeys, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.ACCOUNT_PREFIX + attr.Tenant); err != nil { + return err + } + *reply = len(accountKeys) + + return +} + // Get balance func (apiv2 *APIerSv2) GetAccount(attr *utils.AttrGetAccount, reply *engine.Account) error { tag := utils.ConcatenatedKey(attr.Tenant, attr.Account) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index d84a1b6a7..0f71883e4 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -434,6 +434,10 @@ type AttrGetAccounts struct { Filter map[string]bool } +type AttrGetAccountsCount struct { + Tenant string +} + type ArgsCache struct { DestinationIDs []string ReverseDestinationIDs []string