diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go index 0c0212049..4c94167df 100644 --- a/apier/v1/thresholds.go +++ b/apier/v1/thresholds.go @@ -74,8 +74,11 @@ func (apierV1 *ApierV1) GetThresholdProfile(arg *utils.TenantID, reply *engine.T } // GetThresholdProfileIDs returns list of thresholdProfile IDs registered for a tenant -func (apierV1 *ApierV1) GetThresholdProfileIDs(tenant string, thPrfIDs *[]string) error { - prfx := utils.ThresholdProfilePrefix + tenant + ":" +func (apierV1 *ApierV1) GetThresholdProfileIDs(args utils.TenantArgWithPaginator, thPrfIDs *[]string) error { + if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) + } + prfx := utils.ThresholdProfilePrefix + args.Tenant + ":" keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) if err != nil { return err @@ -87,7 +90,7 @@ func (apierV1 *ApierV1) GetThresholdProfileIDs(tenant string, thPrfIDs *[]string for i, key := range keys { retIDs[i] = key[len(prfx):] } - *thPrfIDs = retIDs + *thPrfIDs = args.PaginateStringSlice(retIDs) return nil } diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index 7b5a5f773..b06da489d 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -339,7 +339,7 @@ func testV1TSGetThresholdsAfterRestart(t *testing.T) { func testv1TSGetThresholdProfileIDs(t *testing.T) { expected := []string{"THD_STATS_1", "THD_STATS_2", "THD_STATS_3", "THD_RES_1", "THD_CDRS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"} var result []string - if err := tSv1Rpc.Call("ApierV1.GetThresholdProfileIDs", "cgrates.org", &result); err != nil { + if err := tSv1Rpc.Call(utils.ApierV1GetThresholdProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{"cgrates.org"}}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) diff --git a/console/threshold.go b/console/threshold.go index 802de7c19..7192af77e 100644 --- a/console/threshold.go +++ b/console/threshold.go @@ -26,7 +26,7 @@ import ( func init() { c := &CmdGetThreshold{ name: "threshold", - rpcMethod: "ApierV1.GetThresholdProfile", + rpcMethod: utils.ApierV1GetThresholdProfile, rpcParams: &utils.TenantIDWithArgDispatcher{}, } commands[c.Name()] = c diff --git a/console/threshold_ids.go b/console/threshold_ids.go new file mode 100644 index 000000000..9398bb128 --- /dev/null +++ b/console/threshold_ids.go @@ -0,0 +1,64 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetThresholdIDs{ + name: "threshold_ids", + rpcMethod: utils.ApierV1GetThresholdProfileIDs, + rpcParams: &utils.TenantArgWithPaginator{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +type CmdGetThresholdIDs struct { + name string + rpcMethod string + rpcParams *utils.TenantArgWithPaginator + *CommandExecuter +} + +func (self *CmdGetThresholdIDs) Name() string { + return self.name +} + +func (self *CmdGetThresholdIDs) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetThresholdIDs) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &utils.TenantArgWithPaginator{} + } + return self.rpcParams +} + +func (self *CmdGetThresholdIDs) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetThresholdIDs) RpcResult() interface{} { + atr := []string{} + return &atr +} diff --git a/console/threshold_remove.go b/console/threshold_remove.go index adea61cc6..c1f878693 100644 --- a/console/threshold_remove.go +++ b/console/threshold_remove.go @@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils" func init() { c := &CmdRemoveThreshold{ name: "threshold_remove", - rpcMethod: "ApierV1.RemoveThresholdProfile", + rpcMethod: utils.ApierV1RemoveThresholdProfile, rpcParams: &utils.TenantIDWithCache{}, } commands[c.Name()] = c diff --git a/console/threshold_set.go b/console/threshold_set.go index 2751685b6..e3f47c124 100644 --- a/console/threshold_set.go +++ b/console/threshold_set.go @@ -18,12 +18,15 @@ along with this program. If not, see package console -import v1 "github.com/cgrates/cgrates/apier/v1" +import ( + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) func init() { c := &CmdSetThreshold{ name: "threshold_set", - rpcMethod: "ApierV1.SetThresholdProfile", + rpcMethod: utils.ApierV1SetThresholdProfile, rpcParams: &v1.ThresholdWithCache{}, } commands[c.Name()] = c diff --git a/utils/consts.go b/utils/consts.go index e311957e3..eefd90f11 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -790,6 +790,10 @@ const ( ThresholdSv1GetThresholdIDs = "ThresholdSv1.GetThresholdIDs" ThresholdSv1Ping = "ThresholdSv1.Ping" ThresholdSv1GetThresholdsForEvent = "ThresholdSv1.GetThresholdsForEvent" + ApierV1GetThresholdProfileIDs = "ApierV1.GetThresholdProfileIDs" + ApierV1GetThresholdProfile = "ApierV1.GetThresholdProfile" + ApierV1RemoveThresholdProfile = "ApierV1.RemoveThresholdProfile" + ApierV1SetThresholdProfile = "ApierV1.SetThresholdProfile" ) // StatS APIs