mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added GetRatingProfileIDs
This commit is contained in:
committed by
Dan Christian Bogos
parent
ee148bf3e4
commit
c831f5749a
@@ -393,6 +393,27 @@ func (self *ApierV1) SetRatingProfile(attrs utils.AttrSetRatingProfile, reply *s
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRatingProfileIDs returns list of resourceProfile IDs registered for a tenant
|
||||
func (apierV1 *ApierV1) GetRatingProfileIDs(args utils.TenantArgWithPaginator, rsPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
prfx := utils.RATING_PROFILE_PREFIX + "*out:" + args.Tenant + ":"
|
||||
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
retIDs := make([]string, len(keys))
|
||||
for i, key := range keys {
|
||||
retIDs[i] = key[len(prfx):]
|
||||
}
|
||||
*rsPrfIDs = args.PaginateStringSlice(retIDs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ApierV1) GetRatingProfile(attrs utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Subject"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
|
||||
@@ -819,6 +819,14 @@ func TestApierV1GetRatingProfile(t *testing.T) {
|
||||
if err := rater.Call("ApierV1.GetRatingProfile", attrGetRatingPlan, &rpl); err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error on ApierV1.GetRatingProfile, recived : %+v", err)
|
||||
}
|
||||
|
||||
expectedIds := []string{"call:dan", "call:*any"}
|
||||
var result []string
|
||||
if err := rater.Call(utils.ApierV1GetRatingProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expectedIds) != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
// Test here ReloadCache
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdGetRatingProfile{
|
||||
name: "ratingprofile",
|
||||
rpcMethod: "ApierV1.GetRatingProfile",
|
||||
rpcMethod: utils.ApierV1GetRatingProfile,
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdRemRatingProfile{
|
||||
name: "ratingprofile_rem",
|
||||
rpcMethod: "ApierV1.RemoveRatingProfile",
|
||||
rpcMethod: utils.ApierV1RemoveRatingProfile,
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdSetRatingProfile{
|
||||
name: "ratingprofile_set",
|
||||
rpcMethod: "ApierV1.SetRatingProfile",
|
||||
rpcMethod: utils.ApierV1SetRatingProfile,
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
|
||||
64
console/rattingprofile_ids.go
Normal file
64
console/rattingprofile_ids.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetRatingProfileIDs{
|
||||
name: "ratingprofil_ids",
|
||||
rpcMethod: utils.ApierV1GetRatingProfileIDs,
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetRatingProfileIDs struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *utils.TenantArgWithPaginator
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdGetRatingProfileIDs) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdGetRatingProfileIDs) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetRatingProfileIDs) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = new(utils.TenantArgWithPaginator)
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetRatingProfileIDs) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetRatingProfileIDs) RpcResult() interface{} {
|
||||
var s []string
|
||||
return &s
|
||||
}
|
||||
@@ -728,6 +728,10 @@ const (
|
||||
ApierV1RemoveFilter = "ApierV1.RemoveFilter"
|
||||
ApierV1SetFilter = "ApierV1.SetFilter"
|
||||
ApierV1GetFilterIDs = "ApierV1.GetFilterIDs"
|
||||
ApierV1GetRatingProfile = "ApierV1.GetRatingProfile"
|
||||
ApierV1RemoveRatingProfile = "ApierV1.RemoveRatingProfile"
|
||||
ApierV1SetRatingProfile = "ApierV1.SetRatingProfile"
|
||||
ApierV1GetRatingProfileIDs = "ApierV1.GetRatingProfileIDs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user