mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding Apier.SetTPDestination
This commit is contained in:
@@ -25,17 +25,17 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type AttrGetTPDestinations struct {
|
||||
type AttrGetTPDestination struct {
|
||||
TPid string
|
||||
DestinationsTag string
|
||||
DestinationId string
|
||||
}
|
||||
|
||||
// Return destinations profile for a destination tag received as parameter
|
||||
func (self *Apier) GetTPDestinations(attrs AttrGetTPDestinations, reply *rater.Destination) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationsTag"}); len(missing) != 0 { //Params missing
|
||||
func (self *Apier) GetTPDestination(attrs AttrGetTPDestination, reply *rater.Destination) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if dst, err := self.StorDb.GetTPDestination(attrs.TPid, attrs.DestinationsTag); err != nil {
|
||||
if dst, err := self.StorDb.GetTPDestination(attrs.TPid, attrs.DestinationId); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if dst == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
@@ -44,3 +44,20 @@ func (self *Apier) GetTPDestinations(attrs AttrGetTPDestinations, reply *rater.D
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrSetTPDestination struct {
|
||||
TPid string
|
||||
DestinationId string
|
||||
Prefixes []string
|
||||
}
|
||||
|
||||
func (self *Apier) SetTPDestination(attrs AttrSetTPDestination, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId", "Prefixes"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if err := self.StorDb.SetTPDestination(attrs.TPid, &rater.Destination{attrs.DestinationId, attrs.Prefixes}); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
*reply = "OK"
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ CREATE TABLE `tp_rate_profiles` (
|
||||
`subject` varchar(64) NOT NULL,
|
||||
`rates_fallback_subject` varchar(64),
|
||||
`rates_timing_tag` varchar(24) NOT NULL,
|
||||
`activation_time` char(3) NOT NULL, ???? char(3)
|
||||
`activation_time` char(20) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
|
||||
@@ -58,6 +58,7 @@ type DataStorage interface {
|
||||
GetDestination(string) (*Destination, error)
|
||||
SetDestination(*Destination) error
|
||||
GetTPDestination(string, string) (*Destination, error)
|
||||
SetTPDestination(string, *Destination) error
|
||||
GetActions(string) (Actions, error)
|
||||
SetActions(string, Actions) error
|
||||
GetUserBalance(string) (*UserBalance, error)
|
||||
|
||||
@@ -78,6 +78,10 @@ func (ms *MapStorage) GetTPDestination(tpid, destTag string) (*Destination, erro
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetTPDestination(tpid string, dest *Destination) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetActions(key string) (as Actions, err error) {
|
||||
if values, ok := ms.dict[ACTION_PREFIX+key]; ok {
|
||||
err = ms.ms.Unmarshal(values, &as)
|
||||
|
||||
@@ -152,6 +152,11 @@ func (ms *MongoStorage) GetTPDestination(tpid, destTag string) (*Destination, er
|
||||
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetTPDestination(tpid string, dest *Destination) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
|
||||
func (ms *MongoStorage) GetActions(key string) (as Actions, err error) {
|
||||
result := AcKeyValue{}
|
||||
err = ms.db.C("actions").Find(bson.M{"key": key}).One(&result)
|
||||
|
||||
@@ -107,6 +107,11 @@ func (rs *RedisStorage) GetTPDestination(tpid, destTag string) (*Destination, er
|
||||
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetTPDestination(tpid string, dest *Destination) error {
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
|
||||
func (rs *RedisStorage) GetActions(key string) (as Actions, err error) {
|
||||
var values string
|
||||
if values, err = rs.db.Get(ACTION_PREFIX + key); err == nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type SQLStorage struct {
|
||||
@@ -78,6 +79,15 @@ func (sql *SQLStorage) GetTPDestination(tpid, destTag string) (*Destination, err
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (sql *SQLStorage) SetTPDestination(tpid string, dest *Destination) error {
|
||||
for _,prefix := range dest.Prefixes {
|
||||
if _,err := sql.Db.Exec(fmt.Sprintf("INSERT INTO tp_destinations (tpid, tag, prefix) VALUES( '%s','%s','%s')",tpid, dest.Id, prefix));err!=nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return errors.New(utils.ERR_NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
func (sql *SQLStorage) GetActions(string) (as Actions, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user