Adding GetTPDestinationIds API method

This commit is contained in:
DanB
2013-07-05 08:46:54 +02:00
parent db62f2cc85
commit 25df692872
7 changed files with 53 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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