From 2aedbcdff4df3021984464b0b3e3156db38964dc Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 8 Dec 2015 12:54:19 +0200 Subject: [PATCH] added get action plan api + console --- apier/v1/accounts.go | 2 +- apier/v1/apier.go | 25 +++++++++++++++ console/actionplan_get.go | 66 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 console/actionplan_get.go diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go index 8f36b63a8..087cb614e 100644 --- a/apier/v1/accounts.go +++ b/apier/v1/accounts.go @@ -252,7 +252,7 @@ func (self *ApierV1) RemoveAccount(attr utils.AttrRemoveAccount, reply *string) // delete without preserving order at.AccountIds[i] = at.AccountIds[len(at.AccountIds)-1] at.AccountIds = at.AccountIds[:len(at.AccountIds)-1] - i -= 1 + i-- changed = true } } diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 38157f5a8..15ce611c9 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -775,6 +775,31 @@ func (self *ApierV1) SetActionPlan(attrs AttrSetActionPlan, reply *string) error return nil } +type AttrGetActionPlan struct { + Id string +} + +func (self *ApierV1) GetActionPlan(attr AttrGetActionPlan, reply *[]engine.ActionPlans) error { + var result []engine.ActionPlans + if attr.Id == "" || attr.Id == "*" { + aplsMap, err := self.RatingDb.GetAllActionPlans() + if err != nil { + return err + } + for _, apls := range aplsMap { + result = append(result, apls) + } + } else { + apls, err := self.RatingDb.GetActionPlans(attr.Id, false) + if err != nil { + return err + } + result = append(result, apls) + } + *reply = result + return nil +} + type AttrAddActionTrigger struct { ActionTriggersId string Tenant string diff --git a/console/actionplan_get.go b/console/actionplan_get.go new file mode 100644 index 000000000..af17a0aed --- /dev/null +++ b/console/actionplan_get.go @@ -0,0 +1,66 @@ +/* +Rating system designed to be used in VoIP Carriers World +Copyright (C) 2012-2015 ITsysCOM + +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/apier/v1" + "github.com/cgrates/cgrates/engine" +) + +func init() { + c := &CmdGetActionPlan{ + name: "actionplan_get", + rpcMethod: "ApierV1.GetActionPlan", + rpcParams: &v1.AttrGetActionPlan{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetActionPlan struct { + name string + rpcMethod string + rpcParams *v1.AttrGetActionPlan + *CommandExecuter +} + +func (self *CmdGetActionPlan) Name() string { + return self.name +} + +func (self *CmdGetActionPlan) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetActionPlan) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &v1.AttrGetActionPlan{} + } + return self.rpcParams +} + +func (self *CmdGetActionPlan) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetActionPlan) RpcResult() interface{} { + s := make([]*engine.ActionPlans, 0) + return &s +}