Adding Apier.SetTPDestination

This commit is contained in:
DanB
2013-07-03 23:01:37 +02:00
parent 00e48bc23a
commit 7e308dca52
7 changed files with 48 additions and 6 deletions

View File

@@ -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
}

View File

@@ -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`)
);

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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
}