diff --git a/apier/tpdestinations.go b/apier/tpdestinations.go index d89ca0749..ddc5d7ef5 100644 --- a/apier/tpdestinations.go +++ b/apier/tpdestinations.go @@ -25,6 +25,21 @@ import ( "github.com/cgrates/cgrates/utils" ) +// Return destinations profile for a destination tag received as parameter +func (self *Apier) GetTPDestinationIds(TPid string, reply *[]string) error { + if TPid == "" { + return fmt.Errorf("%s:TPid", utils.ERR_MANDATORY_IE_MISSING) + } + if ids, err := self.StorDb.GetTPDestinationIds(TPid); err != nil { + return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) + } else if ids == nil { + return errors.New(utils.ERR_NOT_FOUND) + } else { + *reply = ids + } + return nil +} + type AttrGetTPDestination struct { TPid string DestinationId string diff --git a/docs/apicalls.rst b/docs/apicalls.rst index fd62ade7b..12bc1f79e 100644 --- a/docs/apicalls.rst +++ b/docs/apicalls.rst @@ -165,22 +165,6 @@ Example Reply: '{"Reply": {"Tag": "DAN_NET", "Prefixes": ["4917", "4918"]}}' -**DeleteTPDestination** - Delets a destination - -Parametrs: - -TPid - A string containing traiff plan id - -Tag - A destination tag string - -Example - DeleteTPDestination("1dec2012", "DAN_NET") - - Replay: '{"Reply": "ok"}' - **GetAllTPDestinations** Get all destinations diff --git a/rater/storage_interface.go b/rater/storage_interface.go index 2b743c94d..05db40715 100644 --- a/rater/storage_interface.go +++ b/rater/storage_interface.go @@ -57,6 +57,7 @@ type DataStorage interface { SetRatingProfile(*RatingProfile) error GetDestination(string) (*Destination, error) SetDestination(*Destination) error + GetTPDestinationIds(string) ([]string,error) ExistsTPDestination(string, string) (bool, error) GetTPDestination(string, string) (*Destination, error) SetTPDestination(string, *Destination) error diff --git a/rater/storage_map.go b/rater/storage_map.go index 7c1d89390..cdf71578a 100644 --- a/rater/storage_map.go +++ b/rater/storage_map.go @@ -73,6 +73,11 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) { return } +func (ms *MapStorage) GetTPDestinationIds(tpid string) ([]string, error) { + return nil, errors.New(utils.ERR_NOT_IMPLEMENTED) +} + + func (ms *MapStorage) ExistsTPDestination(tpid, destTag string) (bool, error) { return false, errors.New(utils.ERR_NOT_IMPLEMENTED) } diff --git a/rater/storage_mongo.go b/rater/storage_mongo.go index 5e1a8ab3d..1603c7007 100644 --- a/rater/storage_mongo.go +++ b/rater/storage_mongo.go @@ -147,6 +147,10 @@ func (ms *MongoStorage) SetDestination(dest *Destination) error { return ms.db.C("destinations").Insert(dest) } +func (ms *MongoStorage) GetTPDestinationIds(tpid string) ([]string, error) { + return nil, errors.New(utils.ERR_NOT_IMPLEMENTED) +} + func (ms *MongoStorage) ExistsTPDestination(tpid, destTag string) (bool, error) { return false, errors.New(utils.ERR_NOT_IMPLEMENTED) } diff --git a/rater/storage_redis.go b/rater/storage_redis.go index c69d4576b..613d1c5ee 100644 --- a/rater/storage_redis.go +++ b/rater/storage_redis.go @@ -102,6 +102,10 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) { return } +func (rs *RedisStorage) GetTPDestinationIds(tpid string) ([]string, error) { + return nil, errors.New(utils.ERR_NOT_IMPLEMENTED) +} + func (rs *RedisStorage) ExistsTPDestination(tpid, destTag string) (bool, error) { return false, errors.New(utils.ERR_NOT_IMPLEMENTED) } diff --git a/rater/storage_sql.go b/rater/storage_sql.go index 98152da70..da515053d 100644 --- a/rater/storage_sql.go +++ b/rater/storage_sql.go @@ -54,6 +54,30 @@ func (sql *SQLStorage) SetDestination(d *Destination) (err error) { return } +// Extracts destinations from StorDB on specific tariffplan id +func (sql *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) { + rows, err := sql.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_DESTINATIONS, tpid)) + if err != nil { + return nil, err + } + defer rows.Close() + ids:= []string{} + i := 0 + for rows.Next() { + i++ //Keep here a reference so we know we got at least one prefix + var id string + err = rows.Scan(&id) + if err != nil { + return nil, err + } + ids = append(ids, id) + } + if i == 0 { + return nil, nil + } + return ids, nil +} + func (sql *SQLStorage) ExistsTPDestination(tpid, destTag string) (bool, error) { var exists bool err := sql.Db.QueryRow(fmt.Sprintf("SELECT EXISTS (SELECT 1 FROM %s WHERE tpid='%s' AND tag='%s')", utils.TBL_TP_DESTINATIONS, tpid, destTag)).Scan(&exists)