mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Adding GetTPDestinationIds API method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user